我正在使用 primefaces 处理复杂的表单。我需要根据复选框的值隐藏表单的一部分
<p:selectBooleanButton id="input1" .... />
<p:inputText id="input2" />
<!-- the boolean checkbox -->
<p:selectBooleanCheckbox id="checkBox1" value="#{bbean.someBoolValue}" >
<p:ajax event="change" update=":#{p:component('someParentcComponentsId')}" />
</p:selectBooleanCheckbox>
<!-- some input fields here. These will be rendered depending checkBox1 value -->
<p:panel rendered="#{bbean.someBoolValue}" id="hiddingPanel">
<h:panelGrid columns="2" >
<p:inputText id="input3" />
</h:panelGrid>
</p:panel>
到目前为止,我已经完成了这项工作,因此当单击 checkBox1
时,hiddingPanel
会显示或隐藏。但有一个问题:该表单中每个输入的值(例如 input1
、input2
)都丢失了,因为 'change' ajax 事件没有提交它们的值。
如何确保在更新表单之前提交了所有 输入值?
最佳答案
只需确保您仅更新真正需要更新的部分。
<p:selectBooleanCheckbox id="checkBox1" value="#{bbean.someBoolValue}" >
<p:ajax event="change" update="hiddingPanel" />
</p:selectBooleanCheckbox>
<!-- some input fields here. These will be rendered depending checkBox1 value -->
<p:panel id="hiddingPanel">
<h:panelGrid columns="2" rendered="#{bbean.someBoolValue}">
<p:inputText id="input3" />
</h:panelGrid>
</p:panel>
请注意,我将 rendered
移到了它的直接子节点,原因在这里解释:Why do I need to nest a component with rendered="#{some}" in another component when I want to ajax-update it?
关于ajax - 如何提交表单,来自 p :selectBooleanCheckbox change event,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20067112/