4 Replies Latest reply on Apr 17, 2007 12:26 AM by Sergey Smirnov

    How to aovid validations, when submitting AJAX request using

    Chetan Kadam Newbie

      I have a form with some fields, which are marked as required. Then there is a <h:selectOneRadio> button control. When user selects the radio-button, I want to show/hide certain controls (which are wrapped inside a4j:outputPanel)

      <h:selectOneRadio id="type" value="#{dataSourceForm.dataSourceType}" disabled="#{dataSourceForm.editMode}" >
       <f:selectItems value="#{dataSourceForm.dataSourceTypeList}"/>
       <a4j:support event="onchange" reRender="acct_num_fields,role_fields" />
      </h:selectOneRadio>
      


      Now, whats happenning is, if users were to select the radio-button, Form does get submitted. But then in JSF Lifecycles, it errors out since some of the required fields are not filled in yet.

      Is it possible to simply update the model values & jump to renderResponse phase (there by skipping validations on all other fields, which are not filled in by user yet)

      Thanks.



        • 1. Re: How to aovid validations, when submitting AJAX request u
          Sergey Smirnov Master

          Surround your selectOPneRadio with <a4j:region>

          • 2. Re: How to aovid validations, when submitting AJAX request u
            Chetan Kadam Newbie

            Sergey, thanks for quick reply.

            a4j region work. But, I also managed to get this working by defining ValueChangeListener & immediate=true on selectOneRadio, And then forcing RenderResponse on valueChangeListener code. Of course seems like, a4j region is lot cleaner, as I don't have to write any code.

            However, now I am running into another issue: I am using the value of radio button to control "rendered" property of couple of Label / Input controls. I see in the AjaxResponse, to be rendered controls are returned from the server. But then it fails on the client side, when updating the HTML.

            debug[19:36:12,715]: Attempt to update part of page for Id: dataSourceForm:acctNum
            debug[19:36:12,715]: call getElementById for id= dataSourceForm:acctNum
            warn[19:36:12,731]: Node for replace by response with id dataSourceForm:acctNum not found in document


            There controls were not rendered by default on the page. But upon selection of radioButton, this extra markup should be rendered.

            Obviously I am missing something here.

            • 3. Re: How to aovid validations, when submitting AJAX request u
              Chetan Kadam Newbie

              Here is markup that needs to be conditionally rendered, based on radio button selection.

              <tr>
               <td class="formLabel">
               <h:outputLabel for="roleId" value="Role Id:" styleClass="required" />
               </td>
               <td>
               <h:inputText value="#{dataSourceForm.roleId}" id="roleId" size="25" required="true"
               rendered="#{!dataSourceForm.editMode}">
               <f:validateLength maximum="50" />
               </h:inputText>
               <h:outputText value="#{dataSourceForm.roleId}" rendered="#{dataSourceForm.editMode}" /> </td>
              </tr>


              I tried wrapping whole TableRow inside a4j:outputPanel, and assigning rendered property to that (based on selected radio-buttons). But for some reason, these controls get rendered at the top of the page, and not inside the table row as expected.


              • 4. Re: How to aovid validations, when submitting AJAX request u
                Sergey Smirnov Master

                surround this input with <a4j:outputPanel layout="none">


                P.S. Just to prevent your next question:
                #{dataSourceForm} should be a session scope bean OR saved with a4j:keepAlive component. Otherwise, the value will not be processed