Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validator.validate isn't filling the object name #826

Closed
jbdeandrade opened this issue Oct 1, 2014 · 3 comments · Fixed by #833
Closed

Validator.validate isn't filling the object name #826

jbdeandrade opened this issue Oct 1, 2014 · 3 comments · Fixed by #833
Assignees
Labels

Comments

@jbdeandrade
Copy link

Ao fazer a validação com o validator.validate da seguinte forma:

public void adicionarForm(Filial filial) {
     validator.validate(filial);  

    //
}

não é possível capturar o erro na view da utilizando:

${errors.from('filial.nomeFantasia')}
@garcia-jj
Copy link
Member

I'll answer for this issue in english because its our default language to talk here.

This is not a bug, but an expected behavior because using manual validation we can't discovery the name of instance you trying to validate. I'll explain.

In the automatic validation we can easily discovery the parameter name using Paranamer. If you have a controller method called void add(User user), we know that the parameter name is user, because the code is compiled with this meta information.

In the manual validation you call the method with signature Validation.validate(Object object). So we can discovery that the parameter name is object, but we can't discovery the name of instance object you pass as argument. Using this code as example:

public void add(User user, User anotherUser) {
    validation.validate(user);
    validation.validate(anotherUser);
}

In runtime there is no way to discovery that the instance passed to validate method is instance. And neither for the second argument.

May we can add a method validate(String alias, Object objectToValidate) to allow users to define an alias to prepend in category name, but this can breaks backwards compatibility, because we are adding a new method in an interface, and users who migrates to the new version will have problems.

@lucascs @Turini What you think about this case?

Note: I'll change the issue title to allow a better explanation about the case

@garcia-jj garcia-jj changed the title validator.validate (erro) Validator.validate isn't filling the object name Oct 1, 2014
@lucascs
Copy link
Member

lucascs commented Oct 3, 2014

👍 to add the validate with alias on the next major version

@Turini
Copy link
Member

Turini commented Oct 7, 2014

indeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants