2 Replies Latest reply on Jul 17, 2009 11:53 AM by Y E

    Problem with a4j:commandButton and validation error messages

    Y E Newbie


      I have a form that, at some point, I need to submit to the database.
      Initially I had a h:commandButton that was calling the corresponding persist method of the Home object:

      <h:commandButton id="save"

      That, of course, worked fine in terms of showing the error messages - if I tried to submit the form with a required field missing - an error message appeared next to the field.

      Due to the nature of the application I had to replace that button with a:commandButton and it now looks like this:

      <a:commandButton id="persist"  
                    value="Save" action="#{myAction.doSomething}"
                reRender="duplicatesList" >
         <a:jsFunction   name="persistmyEntity" action="#{myEntityHome.persist}" />  
         <a:jsFunction   name="setActionPersist" action="#{myEntityHome.setActionPersist()}" 

      The problem I face is that now the error messages are not displayed. The entity is not persisted, because it fails validation and I get the following message:

      WARNING: FacesMessage(s) have been enqueued, but may not have been displayed

      I guess this problem is related to the use of a4j:commandButton instead of h:commandButton, but I don't know how to fix it.

      I read a discussion that relates to the same error message, but it seems to be a diferent problem.

      Thank you in advance for your help.

        • 1. Re: Problem with a4j:commandButton and validation error messages
          Arbi Sookazian Master

          I recently posted a similar problem.

          When you see:

          WARNING: FacesMessage(s) have been enqueued, but may not have been displayed 

          check which element (field) in the form is being referenced in the error message and reRender that field.

          The root cause of this warning is that there is a validation msg, for example, and ultimately a FacesMessage instance that has been added to FacesMessages object but has not been rendered on your JSF page.  So all you typically need to do is reRender the appropriate component/field.

          • 2. Re: Problem with a4j:commandButton and validation error messages
            Y E Newbie

            Thanks John,

            that did solve the problem.

            Solving this issue, however, I stumbled across something else. It may actually be more of an AJAX issue than a Seam one, but I'll ask anyway.

            In the same form I have an <a:region> element that contains an input text field and a command button:

                 <s:decorate id="myInputField" >
                 <ui:define name="label">Field</ui:define>
                 <h:inputText   immediate="true"
                           value="#{myEntityHome.myAttr}" >
                      <a:support event="onblur" reRender="myInputField"  />                   
                 <a:commandButton value="Lookup" image="img/search.GIF" ajaxSingle="true"  
                                   if (#{!someBean.otherCondition}) 
                                   // do something else

            The input field is a required one.

            The issue is that if I submit the form and some of the required fields, including this one, are missing - when I reRender the form in order to show the validation messages, only the validation message for this field is displayed. Only after I type a value and submit again, I can see  the messages for the rest of the missing required fields.

            What can I do to make sure that I can see all validation error messages the first time I submit the form?

            Thanks in advance.