gpt4 book ai didi

jsf - PrimeFaces 嵌套形式位于 p :dialog with appendTo="@(body) 内

转载 作者:行者123 更新时间:2023-12-02 13:41:36 25 4
gpt4 key购买 nike

我有这个片段:

<h:form id="form">

<!-- other content -->

<p:panel id="panel" header="test">
<p:inputText id="input1" value="#{viewScope.prop1}" required="true" />
<p:commandButton id="button1" process="@form" update="@form @widgetVar(dialog)"
oncomplete="PF('dialog').show()" value="ok" />
</p:panel>

<!-- other content -->

</h:form>

<p:dialog id="dialog" header="dialog" widgetVar="dialog" modal="true">
<h:form id="form2">
<p:inputText id="input2" value="#{viewScope.prop1}" required="true" />
<p:commandButton id="button2" process="@form" update="@form" value="ok" />
</h:form>
</p:dialog>

一切都按预期进行。

我想要实现的是:

<h:form id="form">

<!-- other content -->

<!-- fragment start -->
<!-- this fragment will be on its own file and included via ui:include (or inside composite component) -->
<p:panel id="panel" header="test">
<p:inputText id="input1" value="#{viewScope.prop1}" required="true" />
<p:commandButton id="button1" process="@form" update="@form @widgetVar(dialog)"
oncomplete="PF('dialog').show()" value="ok" />
</p:panel>

<p:dialog id="dialog" header="dialog" widgetVar="dialog" modal="true" appendTo="@(body)">
<h:form id="form2">
<p:inputText id="input2" value="#{viewScope.prop1}" required="true" />
<p:commandButton id="button2" process="@form" update="@form" value="ok" />
</h:form>
</p:dialog>
<!-- fragment end -->

<!-- other content -->

</h:form>

但我没有成功地尝试对 button1 进行 processupdate 的一些组合,导致处理任何内容... input1 甚至正在重置...

那么,如何构建一个可以在片段或复合组件内传送并且从外部 form 中排除的 p:dialog

请注意使用:

<h:form id="form">

<!-- other content -->

<ui:include src="panel.xhtml" />

<!-- other content -->

</h:form>

<ui:include src="dialog.xhtml" />

不是一个可接受的解决方案。

我使用的是 JSF 2.2.8 (mojarra) 和 PF 5.1

最佳答案

最后,我找到了一种使用 OmniFaces 的方法,其中 <o:moveComponent /> :

页面:

<h:form id="form">

<!-- other content -->

<ui:include src="/fragment/with/inner/form.xhtml" />

<!-- other content -->

</h:form>

片段:

<ui:composition>    
<p:inputText id="outerText" value="#{viewScope.text}" />

<p:commandButton id="openButton" process="@form" update="@widgetVar(testDialog)"
oncomplete="PF('testDialog').show()" value="open" />
<o:moveComponent id="move" for=":#{facesContext.viewRoot.clientId}" destination="ADD_LAST">
<h:form id="innerForm">
<p:dialog id="dialog" widgetVar="testDialog" header="test dialog">
<p:inputText id="innerText" value="#{viewScope.text}" />

<f:facet name="footer">
<p:commandButton id="confirmButton" process="@form" update=":form"
oncomplete="if(!args.validationFailed) PF('testDialog').hide()"
value="submit" />
</f:facet>
</p:dialog>
</h:form>
</o:moveComponent>
</ui:composition>

这会导致一些警告:

WARNING Unable to save dynamic action with clientId 'form:innerForm:dialog' because the UIComponent cannot be found
WARNING Unable to save dynamic action with clientId 'form:innerForm:innerText' because the UIComponent cannot be found
WARNING Unable to save dynamic action with clientId 'form:innerForm:confirmButton' because the UIComponent cannot be found

因为恢复的组件不会在后续 RESTORE_VIEW 中重新删除用于回发。

对于我的实验来说,这些警告是无害的,可以安全地忽略。

但是我打开了a pull request最终修复它。

关于jsf - PrimeFaces 嵌套形式位于 p :dialog with appendTo="@(body) 内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26603894/

25 4 0