I have this component:
<ice:form style="width: 45%;" partialSubmit="true" >
<ice:inputText id="cc" required="true" partialSubmit="true" immediate="true"
value="#{userAction.username}">
<f:validator validatorId="passwordValidator" />
<ice:message style="color: red;" id="ageError" for="cc" />
</ice:inputText>
</ice:form>
I have declared the validator in faces config:
<validator>
<validator-id>passwordValidator</validator-id>
<validator-class>com.mydomain.seam_icefaces_test.action.PasswordValidator</validator-class>
</validator>
And the validator java class:
package com.mydomain.seam_icefaces_test.action;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
import org.jboss.seam.faces.FacesMessages;
public class PasswordValidator implements Validator {
@Override
public void validate(FacesContext arg0, UIComponent arg1, Object value)
throws ValidatorException {
String val = (String) value;
if (val.length() == 0)
((UIInput) arg1).setValid(false);
FacesMessages.instance().addToControlFromResourceBundle(arg1.getId(),
"invalid.password");
}
}
I do not understand why this is not firing when it looses focus....
Do you have any ideea?
Thanks.
JSF validators are called during validation fase. They are not called just when control lost the focus. See the lifecycle.