2 Replies Latest reply on Apr 23, 2014 8:54 AM by sam-user

    Richfaces Re-render not calling validation

    sam-user

      I have a Richfaces (3.3.1) page with a form containing number of components. Some of these components are mandatory, so the required attribute is set to true.

      I have a commandButton (C1), which calls a server operation. Based on the result of the server operation a field of type h:selectOneMenu (F1)is populated. This field is mandatory and its value is either manually selected by the user or populated via the server operation.

      The problem appears when the form is submitted without a value in field F1. Naturally the validation fails and the error message “value is required” (or whatever the value of requiredMessage attribute is) is displayed. If the user then executes the server operation the F1 field is populated with the returned value and it is reRendered. It seems, however, that the validation is not being performed on the client side and the field is still displayed as in error (althouth the error message "value required" disapears). Even if the user manually selects a value after that the field is still displayed as invalid. I’ve been searching on the internet, but couldn’t find a similar case.

      Here are some excerpts from my page:

       

      <a:region>

          <s:decorate id="alField" template="#{template}">

              <ui:define name="label">Al</ui:define>

              <h:inputTextarea id="al" maxlength="75"

                  valueChangeListener="#{aEntHome.clearFields}" requiredMessage="Required"

                  required="true" value="#{aEntHome.instance.al}">

                  <f:validator validatorId="stringNotEmtyTrimmedValidator" />

                  <a:support event="onblur" reRender="F1Field" bypassUpdates="true" />

              </h:inputTextarea>

              <a:commandButton value="Search" image="img.GIF" id="searchImg"

                  action="#{lSearch.search}" reRender="F1Field,alField">

              </a:commandButton>

          </s:decorate>

      </a:region>

      <s:decorate id="F1Field" template="#{template}">

          <ui:define name="label">F1</ui:define>

          <h:selectOneMenu value="#{aEntHome.instance.f1}"

              required="true">

              <s:selectItems value="#{listH.f1List}" var="_c"

                  label="#{_c.f1Code}(#{_c.f1Name})" />

              <s:convertEntity />

          </h:selectOneMenu>

      </s:decorate>

       

      And this is the template used for displaying the fields:

       

      <ui:composition xmlns="http://www.w3.org/1999/xhtml"

          xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"

          xmlns:f="http://java.sun.com/jsf/core" xmlns:s="http://jboss.com/products/seam/taglib">

          <div class="prop">

              <s:label styleClass="longName #{invalid?'errors':''}">

                  <ui:insert name="label" />

                  <s:span styleClass="required" rendered="#{required}">*</s:span>

              </s:label>

              <span class="value #{invalid?'errors':''}">

                  <s:validateAll>

                      <ui:insert />

                  </s:validateAll>

              </span>

              <span class="error">

                  <h:graphicImage value="/img/error.gif" rendered="#{invalid}"

                      styleClass="errors" />

                  <s:message styleClass="errors" />

              </span>

          </div>

      </ui:composition>

       

      Could someone suggest what might be going wrong with this code?

      I'd really appreciate any help, as I ran out of ideas.

        • 1. Re: Richfaces Re-render not calling validation
          sivaprasad9394

          Hi,

           

          try to add the <a4j:support event="onChange" reRender="renderID" /> for the h:selectOneMenu.

          Also add ajaxSingle="true" for the a:commandButton because,

           

          Note, that ajaxSingle="true" reduces the upcoming traffic, but does not prevent decoding other input components on the server side. Some JSF components, such as <h:selectOneMenu> do recognize the missing data in the request map value as a null value and try to pass the validation process with a failed result. Thus, use <a4j:region> to limit a part of the component tree that will be processed on the server side when it is required.

           

          When calling the backing bean try to set the   required="true" value of <h:selectOneMenu> by using,defining one new boolean variable in backing bean by defauly as true and after saving or fetching some data change the boolean variable to false.Here the validation will be stopped. OR create a listener using ajax for <h:selectOneMenu> for manually you change the selection of the combobox and try do rerender of fields you want...

          • 2. Re: Richfaces Re-render not calling validation
            sam-user

            Hi Siva,

            I tried your suggestions but there was no difference.

            Also I'm not sure I understand the last paragraph.

            Could you elaborate a bit more?