Suppose I have a username to validate, in this case I need to show username outputText and username inputText field in red color when validation fails along with error message.
I tried to bind all these in a panelgroup so that if validation fails all field should be affected. But simply putting panelgroup is not working.
My backing bean validator
public void emailValidate(FacesContext context,
UIComponent componentToValidate,
Object value)
throws ValidatorException {
String email = value.toString();
if (!Validator.isEmailAddress(email))
{
FacesMessage message =
new FacesMessage(FacesMessage.SEVERITY_ERROR,"Email","Please enter valid email address");
throw new ValidatorException(message);
}
}
My Jsf
<h:panelGroup>
<h:outputText value="Email"/>
<h:message for="emailInput/>
<h:inputText id="emailInput" value="#{mybean.email}" validator="#{mybean.emailValidate}"/>
</h:panelGroup>