A tabular form is validating a input field using a validator method binding plus a standard f:validateLength validator.
<rich:dataTable value="#{menuAdminController.selectedObject.attributes}" var="attribute" id="attributesTable"> <rich:column> <f:facet name="header"> <h:outputText value="Login" /> </f:facet> <h:inputText id="login" value="#{attribute.login}" required="false" valueChangeListener="#{attribute.userValueChanged}" validator="#{attribute.validateUser}"> <f:validateLength maximum="5" /> <!-- TODO: validatorMessage does not get displayed here --> </h:inputText> <rich:message for="login" /> </rich:column> </rich:dataTable> <a4j:commandButton value="#{applicationResources['command.store']}" action="#{menuAdminController.storeAttributes}" oncomplete="if (!hasFacesMessages) Richfaces.hideModalPanel('editPanel');" />
public void validateUser(FacesContext context, UIComponent component, Object value) throws ValidatorException { if (value == null || ((String) value).length() == 0) { return; } try { throw new ValidatorException(new FacesMessageSupport().newFacesMessage(FacesMessage.SEVERITY_ERROR, message)); } catch (DataAccessException e) { throw new ValidatorException(new FacesMessageSupport().newFacesMessage(e)); } }
FacesContext.getCurrentInstance().getClientIdsWithMessages()