Explicit validation for af:input components


Here is a simple way to get around with the red box validation that used to appear on af:input Components upon some validation

<af:inputText value="#{row.bindings.<attributeValue>.inputValue}"
 label="#{bindings.<tableBinding>.hints.<attributeValue>.label}"
 required="#{bindings.<tableBinding>.hints.<attributeValue>.mandatory}"
 columns="#{bindings.<tableBinding>.hints.<attributeValue>.displayWidth}"
 maximumLength="#{bindings.<tableBinding>.hints.<attributeValue>.precision}"
 shortDesc="#{bindings.<tableBinding>.hints.<attributeValue>.tooltip}"
 id="it3" validate="#{MyBean.validate}">

and in the MyBean class we have it like

public void validate(FacesContext facesContext, UIComponent uiComponent, Object value) {
        FacesMessage message = new FacesMessage();
        message.setDetail("Some Errror message");
        message.setSummary("Value Error message");
        message.setSeverity(FacesMessage.SEVERITY_ERROR);
        throw new ValidatorException(message);
}

what are we doing here..

  • Getting the handle to the FacesMessage by explicitly instantiating it
  • Set the Detail,Summary and Severity for the message
  • Throwing the message as a ValidatorException

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s