1

Q: What syntax should i use to exclude a component when submitting a form using primefaces?

Using the process attribute i know how to include components.

<h:inputText id="included"/>
<p:commandButton value="button" process="included" actionListener="#{myBean.doStuff}/>

I've been trying to play around with syntax similiar to what is used in the answer here: How to exclude child component in ajax update of a parent component? but cant get it to work

<h:inputText id="notIncluded" styleClass="notIncluded"/>
<p:commandButton ... process="@(form :not(.notIncluded))"/>

Edit (doing the homework and adding an actual working example): On glassfish 3.1.2.2 and primefaces 3.4.2

When i looked further, the exclusion works fine inside h:panelGrid

<h:form id="aForm">
    <h:panelGrid columns="2">
        <p:inputText id="inc" styleClass="included" required="true" />
        <p:message for="inc" />
        <p:inputText id="notInc" styleClass="notIncluded" required="true" />
        <p:message for="notInc" />

        <p:commandButton value="submit" process="@(form :not(.notIncluded))"
            update=":aForm" />
    </h:panelGrid>
</h:form>

But is no longer excluded inside a similar p:panelGrid

<h:form id="aForm">
    <p:panelGrid columns="2">
        <p:inputText id="inc" styleClass="included" required="true" />
        <p:message for="inc" />
        <p:inputText id="notInc" styleClass="notIncluded" required="true" />
        <p:message for="notInc" />

        <p:commandButton value="submit" process="@(form :not(.notIncluded))"
            update=":aForm" />
    </p:panelGrid>
</h:form>
Community
  • 1
  • 1
Aksel Willgert
  • 11,367
  • 5
  • 53
  • 74
  • 1
    which version Primefaces you are using? have you placed in a single h:form as Balus example? Another suggestion that you can add additionaly '@this' too so commandButton will be executed. – HRgiger Dec 28 '12 at 17:51
  • 1
    Yeah you are right, i removed the information that didnt make it work :) updating in a sec.. – Aksel Willgert Dec 28 '12 at 18:49

1 Answers1

4

I have checked your examples, if you review page source your will notice that p:panelGrid creates table with id. Little bit strange but jQuery selector doesnt access childs when table has an id. If I remove table Id then button works fine. So my solution was giving an id to panelGrid and using this id in selector. p:panelGrid will give same id to table but you need to make sure you add prependId="false" attribute into your h:form:

<h:form id="aForm" prependId="false">
    <p:panelGrid columns="2" id="myGrid">
        <p:inputText id="inc" styleClass="included" required="true" />
        <p:message for="inc" />
        <p:inputText id="notInc" styleClass="notIncluded" required="true" />
        <p:message for="notInc" />

        <p:commandButton value="submit" process="@(#myGrid :not(.notIncluded))"
            update=":aForm" />
    </p:panelGrid>
</h:form>
HRgiger
  • 2,750
  • 26
  • 37