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

Adding support for alias when validates the bean. #833

Merged
merged 4 commits into from
Oct 7, 2014

Conversation

garcia-jj
Copy link
Member

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 inherits DefaultValidator. So may we can wait a new minor release like 4.2.

String category = v.getPropertyPath().toString();
if (isNullOrEmpty(alias)) {
category = alias + "." + category;
}
Copy link
Member Author

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the if :)

@Turini
Copy link
Member

Turini commented Oct 7, 2014

sounds ok to me, but just a question: we really can't get (via reflection or
something like that) the validated class name to avoid doing it manually?

@garcia-jj
Copy link
Member Author

we really can't get (via reflection or
something like that) the validated class name to avoid doing it manually?

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 usuarioFinal, but the parameter name is usuario. So using class name we will force users to use the parameter based on class name.

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 gerente.

So using alias will allow users to validating anything without any limitation.

@garcia-jj
Copy link
Member Author

@Turini @lucascs Ok to merge only in 4.2? May better to use a tag to mark this or we can create a draft release and tag this pull request with this draft release?

@Turini
Copy link
Member

Turini commented Oct 7, 2014

now I see, thanks @garcia-jj.
Yes, I think we can merge it by adding the info on next changelog.

@garcia-jj
Copy link
Member Author

Thank you.

garcia-jj added a commit that referenced this pull request Oct 7, 2014
Adding support for alias when validates the bean.
@garcia-jj garcia-jj merged commit 9d97e7b into master Oct 7, 2014
@garcia-jj garcia-jj deleted the ot-gh826-addingvalidatoralias branch October 7, 2014 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validator.validate isn't filling the object name
2 participants