I\'ve got a little problem here with my application. I\'d like to check if fields password and confirm password match together, so I tried to do it like in the first answer
Class-level constraints are not triggered automatically by JSF during validation phase. You can use only field-level constraints (moreover not all fields are valuated by JSF but only those that are in your facelet).
If you want to use bean validation you can perform validation manually:
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
Set<ConstraintViolation<Test>> violations = validator.validate( this, Default.class );
You can do it in registration method of your bean or after update model phase (but I've never tried it).
Anyway you can use JSF validation instead of bean validation or check the passwords directly in the registration method:
public String registration() {
...
if ( !password.equals(password2) ) {
FacesContext.getCurrentInstance().addMessage( null, new FacesMessage( "Passwords do not match" ) );
return null;
}
...
}