I use JSR303 and create a class-level constraint that compares the password and its confirmation in a form that I will name here as the @SameAs constraint. Ideally, I would like to associate the restriction with the intended purpose (confirmPassword), but obviously the closing bean is not available for password retrieval. - therefore, class level restriction.
I read with interest other posts demonstrating how to use class-level constraints to check relationships, but cannot find anything explaining how the constraint constraint can be configured to bind to a subpath, in which case one of two fields in this regard.
My question is this: how to associate a restriction violation message with the confirmPassword field instead of a top-level object? I tried using the javax.Validator.validate (target, context) context parameter, but adding Node to the validator for @SameAs throws an exception for the next cascade constraint (trying to extract confirmation Password → orderNumber, not order → orderNumber).
At the moment, I resorted to an ugly blog, creating an additional property that stores a restriction message that breaks out for use next to the confirmPassword input field on the web layer.
Of course, I missed something here ... see example below
Thanks for any comments.
Example
@Constraint( validatedBy = { SamePwdAsValidator.class}) public interface SamePwdAs {
java constraints bean-validation
Kingcode
source share