I\'m trying to validate two password fields with JSF but no good until now, I search for it on google but everything was about JSF 1.2 and pretty confusing, I\'m using JSF
With seam 2 you have the component and you don't need to write code. For JSF2 then you have Seam 3 modules, particulary Faces module and Cross-field Form Validation. An example :
First you have to use the s:validateForm tag:
and the corresponding Validator for the password form above would look like this:
@FacesValidator("PasswordValidator")
public class PasswordValidator implements Validator
{
@Inject
@InputField
private String newPassword;
@Inject
@InputField
private String confirmPassword;
@Override
public void validate(final FacesContext context, final UIComponent comp, final Object values) throws ValidatorException
{
if (!confirmPassword.equals(newPassword))
{
throw new ValidatorException(new FacesMessage("Passwords do not match!"));
}
}
}