3 Replies Latest reply on Oct 28, 2007 1:01 AM by mgrouch

    Having commandButton submit only the form fields you want

    Jeff Jo Newbie

      I'm having an issue with form submission not being successful because it trips up on the validation of some of the fields in the form. The general structure is as follows:

      <h:form>
       <h:panelGrid columns="2" id="pgMain" rendered="#{contr.shouldRender}">
      
       <h:panelGrid columns="1" id="pg1">
       <h:inputText id="text1" required="true"/>
       </h:panelGrid>
      
       <h:panelGrid columns="1" id="pg2">
       <a4j:region>
       <h:inputText id="text2" required="true"/>
       <a4j:commandButton action="#{contr.addToList}" reRender="pg2,dt1"/>
       </a4j:region>
       </h:panelGrid>
      
       <a4j:region>
       <h:dataTable id="dt1" value="#{contr.myList}" var="curItem">
       <h:column>
       <h:outputText value="#{curItem}"/>
       </h:column>
       </h:dataTable>
       </a4j:region>
      
       <h:panelGrid columns="1" id="pg3">
       <a4j:commandButton action="#{contr.submitForm}" reRender="pgMain"
       </h:panelGrid>
      
       </h:panelGrid>
      </h:form>
      


      As you can see from the code, the form contains four sections.
      1) A panelGrid with an inputText (text1) that has required = "true"
      2) A panelGrid with an inputText (text2) whose value gets added to the dataTable dt1 when the commandButton with action="#{contrl.addToList}" is fired. This is also required=true, but I only want it to be required when the addToList function is called.
      3) A dataTable displaying values #{contrl.myList}
      4) A panelGrid that submits the form and reRenders pgMain (which is conditionally rendered). In effect after the form is submitted, I want pgMain to disappear.

      I have it working so that when the commandButton contained within pg2 is clicked, the validation for text1 is NOT fired. I do that by only reRendering pg2 and dt1.

      The issue is, when I click the last command button in pg3, I want text1 to be validated, but NOT text2. Right now, the form cannot submit because it is catching the validation for text2.

      I think the problem is because I tell the last commandButton to reRender pgMain which also contains text2, and is therefore being submitted with the form.

      Does anyone have any ideas?