5 Replies Latest reply on Oct 2, 2008 3:15 AM by joblini

    Validation: What Am I Missing

    leesy

      Hi all,


      I'm just trying to get my validation working on my page but I'm not having much luck.  I must be missing something simple so could someone have a quick look at my code below and see if you notice anything out of place.


      Thanks,
      Lee


      The error message is created using:


      getFacesMessages()
                .addToControlFromResourceBundleOrDefault(
                    "customerName",
                    SEVERITY_ERROR,
                    "CustomerExternalIdDuplicate",
                    "A customer with an external ID of {0} already exists.  Please choose another",
                    getInstance().getExternalId());



      My page - a modal dialog included via a4j:include. (I've tested the code out of the modal dialog though and still no luck):


      <h:form id="modalForm">
            
            <h:messages globalOnly="true" />
            
            <fieldset>
            <s:validateAll>
            
            <f:facet name="aroundInvalidField">
              <s:span styleClass="errors" />
            </f:facet>
            <f:facet name="afterInvalidField">
              <s:div styleClass="errors">
                <s:message />
              </s:div>
            </f:facet>
            
            <ul class="layout form">
              <li>
                <label for="customerName">Name:</label>
                <s:decorate>
                  <h:inputText id="customerName" value="#{customerHome.instance.externalId}" />
                </s:decorate>
              </li>
              <li>
                  <label for="customerDisplayName">Display Name:</label>
                  <s:decorate>
                    <h:inputText id="customerDisplayName" value="#{customerHome.instance.displayName}" />
                  </s:decorate>
                </li>
                <li>
                  <label for="customerAccountManager">Account Manager</label>
                  <s:decorate>
                  <h:selectOneListbox id="customerAccountManager" value="#{customerHome.instance.accountManager}">
                    <s:selectItems var="item" value="#{accountManagersList}" label="#{item.displayName}" hideNoSelectionLabel="true"/>
                    <s:convertEntity /> 
                  </h:selectOneListbox>
                  </s:decorate>
                </li>
                <li>
                  <label for="customerDemo">Demo Customer?</label>
                  <s:decorate>
                  <h:selectBooleanCheckbox id="customerDemo" value="#{customerHome.instance.demo}" />
                  </s:decorate>
                </li>
                <li>
                  <a4j:commandButton value="Add New Customer" action="#{customerHome.persist}" reRender="resultsTable"/>
                </li>
              </ul>
            </s:validateAll>
            </fieldset>
      </h:form>



      I'm just constantly getting the error


      INFO: WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
      sourceId=modalForm:j_id103:customerName[severity=(ERROR 2), summary=(A customer with an external ID of abc already exists.  Please choose another), detail=(A customer with an external ID of abc already exists.  Please choose another)]



      The form input described in that error does exist, it just can't seem to link the message to it.  So - any suggestions?

        • 1. Re: Validation: What Am I Missing
          nimo22

          This:


          INFO: WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
          sourceId=modalForm:j_id103:customerName[severity=(ERROR 2),...



          is okay and not a failure!


          It says only, that this message which is enqueued and invisible can be shown when the validation of your specified value does not succeed.


          But one thing, I cannot see: where is your validator in your form?


          Do you use Hibernate-Validators? Are your validator in your entity-Bean?

          • 2. Re: Validation: What Am I Missing
            tamerg

            Add a outputPanel to h:messages and reRender it.

            • 3. Re: Validation: What Am I Missing
              leesy

              It says only, that this message which is enqueued and invisible can be shown when the validation of your
              specified value does not succeed.

              I used the word error in mistake.  I know it's a harmless message.  The trouble though is that the messages aren't showing when as far as I can see, they should be.  I always get this message in my log.



              Do you use Hibernate-Validators? Are your validator in your entity-Bean?

              Yes and Yes :)  I've got annotations like @NotEmpty and various others set in my entities.



              Add a outputPanel to h:messages and reRender it.

              Should I have to do that though?  I've just taken this code from the Seam documentation and some previous code, all which worked fine and had pretty much the same code as above.

              • 4. Re: Validation: What Am I Missing
                nimo22

                The only (important) thing you have missed, is to set the Tag:



                required=true




                in all your components which should be validated:


                for example:


                <h:inputText required="true" ..>




                then, it should be work!



                don't forget to rate:-)

                • 5. Re: Validation: What Am I Missing
                  joblini

                  Try changing


                  <h:messages globalOnly="true" />



                  to


                  <h:messages globalOnly="false" />