Search code examples
validationxhtmlajax4jsf

'requiredMessage' attribute not working in xhtml form. Error message won't display


I have the following code:

Enter a word:
<h:inputText value="#{testfile1.input}" styleClass="textbox" id="inputID" maxlength="100" required="true" requiredMessage="Input should not be blank">
        </h:inputText>
<h:message for="inputID" style="color:red"/>
<a4j:commandButton value="Save" styleClass="button" action="#{testfile1.saveData}"> </a4j:commandButton>

The save button doesn't work if the above field is left blank, which is exactly what i want. But i am unable to display any error message.


Solution

  • Your commandButton is not re-rendering the h:message

    you can wrap the h:message like so to auto-render whenever an ajax request is made...

    <a4j:outputPanel ajaxRendered="true">
        <h:message for="inputID" style="color:red" />
    </a4j:outputPanel>
    

    or...used the rendered attribute on the commandButton (eg. render="@form")