exclude component from process when form is submited (works in h:panelGrid but not in p:panelGrid)

ⅰ亾dé卋堺 提交于 2019-12-23 02:18:33

问题


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>

回答1:


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>


来源:https://stackoverflow.com/questions/14073406/exclude-component-from-process-when-form-is-submited-works-in-hpanelgrid-but-n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!