The real question is: how to create a validator that will access other JSF components other than the component being checked?
Do not try to access components directly; You will regret it. The JSF validation engine works best to prevent spam from entering the model.
bean; - :
public class PasswordValidationBean {
private String input1;
private String input2;
private boolean input1Set;
public void validateField(FacesContext context, UIComponent component,
Object value) {
if (input1Set) {
input2 = (String) value;
if (input1 == null || input1.length() < 6 || (!input1.equals(input2))) {
((EditableValueHolder) component).setValid(false);
context.addMessage(component.getClientId(context), new FacesMessage(
"Password must be 6 chars+ & both fields identical"));
}
} else {
input1Set = true;
input1 = (String) value;
}
}
}
:
<h:form>
Password: <h:inputSecret
validator="#{passwordValidationBean.validateField}"
required="true" />
Confirm: <h:inputSecret
validator="#{passwordValidationBean.validateField}"
required="true" />
<h:commandButton value="submit to validate" />
<h:messages />
</h:form>
, Bean Validation (JSR 303).