-
Notifications
You must be signed in to change notification settings - Fork 329
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
Adding support for alias when validates the bean. #833
Conversation
String category = v.getPropertyPath().toString(); | ||
if (isNullOrEmpty(alias)) { | ||
category = alias + "." + category; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its too evil if I use ternary block here?
category = isNullOrEmpty(alias) ? category : alias + "." + category
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the if
:)
sounds ok to me, but just a question: we really can't get (via reflection or |
Yes, we can get the class name. But won't help us. Using the example in the original issue: public void adicionarForm(Filial filial) {
validator.validate(filial);
} Works fine if I try to discovery the parameter name using class name. But if I have this case: public void adicionarForm(UsuarioFilial usuario) {
validator.validate(usuario);
} Using class name will return Or using this another case: public void adicionarForm(Filial filial) {
validator.validate(filial.getGerente());
} The parameter class is Filial, but I trying to validate a nested property So using alias will allow users to validating anything without any limitation. |
now I see, thanks @garcia-jj. |
Thank you. |
Adding support for alias when validates the bean.
This pull request closes #826.
As discussed before, I added new methods adding an alias parameter. If alias is not null, the value will be prepended to the category. We need this because using method validation we can discover the parameter name, that is added to category. But using manual validation via
Validate.validate
we isn't able to discovery this name.Note: this pull request adds new methods in
Validator
interface, so can break apps that implements this interface but don't inheritsDefaultValidator
. So may we can wait a new minor release like 4.2.