0

I have two panelgrids in my page.

  • In the first panel grid I have two input text with a button. This button should valid only this input text.

  • In the second panelgrid i have 3 input text with a button which
    should validate these 3 text only.

    How can I ensure that on button click in thr first panelgrid , the required=true gets ignored for all elements in the second panel grid.

    Any help would be appreciated.

Tiny
  • 683
  • 5
  • 18
  • 36

1 Answers1

0

If you are using Primefaces you can use partial submit. For your example:

<h:form>
        <p:panelGrid id="grid1">
            <p:inputText required="true" id="inp1" value="#{test.value1}"/>
            <p:inputText required="true" id="inp2" value="#{test.value2}"/>
            <p:commandButton partialSubmit="true" process="@this inp1 inp2" action="#{test.someAction()}" value="validation"  update="grid1"/>
        </p:panelGrid>
        <p:panelGrid id="grid2">
            <p:inputText required="true" id="inp3" value="#{test.value3}"/>
            <p:inputText required="true" id="inp4" value="#{test.value4}"/>
            <p:inputText required="true" id="inp5" value="#{test.value5}"/>
            <p:commandButton partialSubmit="true" process="@this inp3 inp4 inp5" action="#{test.someAction()}" value="validation" update="grid2"/>
        </p:panelGrid>
    </h:form>

Or you can palce grids with buttons in separate forms. Beacuse by default ajax request posts (and validates) values only from current form.

    <h:form>
        <p:panelGrid id="grid1">
            <p:inputText required="true" id="inp1" value="#{test.value1}"/>
            <p:inputText required="true" id="inp2" value="#{test.value2}"/>
            <p:commandButton action="#{test.someAction()}" value="validation"  update="@form"/>
        </p:panelGrid>
    </h:form>
    <h:form>
        <p:panelGrid>
            <p:inputText required="true" id="inp3" value="#{test.value3}"/>
            <p:inputText required="true" id="inp4" value="#{test.value4}"/>
            <p:inputText required="true" id="inp5" value="#{test.value5}"/>
            <p:commandButton  action="#{test.someAction()}" value="validation" update="@form"/>
        </p:panelGrid>
    </h:form>
Artem
  • 371
  • 4
  • 11
  • The desired behavior is not specific to `partialSubmit`, but to `process`. See also http://stackoverflow.com/questions/25339056/understanding-process-and-update-attributes-of-primefaces/ – BalusC Mar 17 '16 at 13:22
  • Thank you Artem and Balus for your valuable comments.. I was able to resolve this by dynamically setting the required attribute to true on button click.. – Tiny Mar 18 '16 at 09:01