Reputation: 9621
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.
Upvotes: 0
Views: 2128
Reputation: 353
A few things... Shouldn't the last part of your code be like
if (val.length() == 0)
{
((UIInput) arg1).setValid(false);
FacesMessages.instance().addToControlFromResourceBundle(arg1.getId(),
"invalid.password");
}
? This might be why your message is not showing up.
Secondly, the Immediate
attribute is not necessary. You can try working without it.
Lastly, try using the validator="#{MyBean.validatePassword}"
attribute in the <ice:inputText>
tag, where validatePassword
is a copy of the validate
method from the PasswordValidator class.
Upvotes: 0
Reputation: 43098
JSF validators are called during validation fase. They are not called just when control lost the focus. See the lifecycle.
Upvotes: 1