Based on a recent BVAL issue [1], I'm proposing to introduce a special constraint annotation attribute, "validationAppliesTo", allowing to specify the required behavior at the usage site:
@EqualPasswords(validationAppliesTo=PARAMETERS)
public void register(String username, String password, String confirmPassword) {
}
@EqualPasswords(validationAppliesTo=ANNOTATED_ELEMENT)
public class ResetPasswordRequest {
String password;
String confirmedPassword;
}
The following rules would apply:
* If a constraint is annotated with @Constraint and @CrossParameterConstraint, it must define a member "validationAppliesTo". The default value should be ANNOTATED_ELEMENT.
* If a constraint is annotated with only one of @Constraint/@CrossParameterConstraint, defining a "validationAppliesTo" member doesn't have any special effect
* Specifying validationAppliesTo=PARAMETERS anywhere except a method causes ConstraintDeclarationException
Any thoughts?
--Gunnar