所以我遇到了 PrimeFaces 的这种问题(这次上面的答案还不够),我也找到了一个解决方案。
我认为部分问题是我在ui:include
递归使用。无论出于何种原因,PrimeFaces 不合理地导致 UI 组件绑定到后端数据不同步;例如,当单击“添加”按钮时,将在 UI 中创建一个新值,但随后会从下面部分的值中删除它的数据,等等......
说明?“[O] 一个 viewscoped bean,一个隐藏字段被添加到表单中以保存回发数据 [;] 如果该字段不包含在流程中,那么 bean 将丢失上下文。” ui:include
这个特殊问题在递归中尤其普遍。解决方案(所有关于p:commandButton
或其他可操作的组件):
- 确保
update
andprocess
指向一个 JSF 组件,而不是一个常规的 HTML 组件。
update
如果下一个范围中断(与绑定不同步)。
- 使用
styleClass
's 进行更新(不是例如 PF ID 或@this:@parent
其他东西),以便使用 jQuery 而不是 PF,例如:@(.fieldset-class)
.
process
whatever scope is being updated. (This is needed for the post-back data so that the Bean keeps its context for the update...) process="@this"
is not needed here, provided that the button is contained by the process value component.
- For all buttons without validation wanted, set
immediate="true"
.
- If none of the above works (which happened with the Add buttons, probably due to
ui:include
recursion), set process="@this"
, immediate="true"
, and update="@none"
, and then oncomplete="remoteCommandName();"
, and have a p:remoteCommand
instead with that name with the process
, immediate
, and update
mentioned in the above points.
ui:include
如果上述方法均无效(与其他一些按钮一起发生,可能是由于在递归中的另一层更深)...环绕h:panelGroup
下一个c:forEach
,然后更新按钮本身的PrimeFaces ID,同时保持其之后调用,如上所述。remoteCommand
- 如果以上都不起作用(这又发生在我身上)......试试下面的代码:
- 在
p:commandButton(s)
:oncomplete="$('.FixButtonSC').click();"
- 在
p:fieldset
带有样式类的 FieldsetSC 中:
<!-- Fix (hidden) button. -->
<p:commandButton id="FixButton" styleClass="FixButtonSC"
process="@this" update="@(.FieldsetSC)" style="display: none;" />
希望有帮助...