I have two fields representing data range ("from" and "to"). I need to check if either both fields are filled on none of them, so only moment there should be validation message shown is when one is filled and not second one. How can I do that? I thied this custom validator and add it to both fields (as JSF doesn't validate empty fields) but it always show that they are not valid.
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
String otherControlId = (String) component.getAttributes().get("otherControlId");
UIInput otherControlInput = (UIInput) context.getViewRoot().findComponent(otherControlId);
Object otherControlValue = otherControlInput.getValue();
if ((value == null && otherControlValue != null) || (value != null && otherControlValue == null)) {
//show message
}
}
otherControlId points to second control ID, and I get a control in validator. But otherControlValue is always null.