问:在使用primefaces提交表单时,我应该使用什么语法来排除组件?
使用process属性我知道如何包含组件。
<h:inputText id="included"/>
<p:commandButton value="button" process="included" actionListener="#{myBean.doStuff}/>
我一直在尝试使用与此处答案中使用的语法类似的语法:How to exclude child component in ajax update of a parent component?但无法使其工作
<h:inputText id="notIncluded" styleClass="notIncluded"/>
<p:commandButton ... process="@(form :not(.notIncluded))"/>
编辑(完成作业并添加实际工作示例): 关于glassfish 3.1.2.2和primefaces 3.4.2
当我进一步观察时,排除在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>
但不再排除类似的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>
答案 0 :(得分:4)
我检查了您的示例,如果您查看了网页来源,您会注意到p:panelGrid
创建了带有ID的表格。有点奇怪,但是当表有id时, jQuery选择器不能访问子节点。如果我删除表ID,那么按钮工作正常。所以我的解决方案是给panelGrid
一个id并在选择器中使用这个id。 p:panelGrid
会向表格提供相同的ID,但您需要确保在h:form中添加prependId="false"
属性:
<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>