Mic*_*tti 7 jsf dialog nested-forms primefaces jsf-2.2
我有这个片段:
<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>
Run Code Online (Sandbox Code Playgroud)
一切都按预期工作.
我想要达到的目的是:
<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>
Run Code Online (Sandbox Code Playgroud)
但我没有成功尝试的某种组合process,并update为button1导致处理任何事情...... input1甚至重新...
那么,如何构建一个p:dialog可以在片段或复合comp中发布并且从外部排除的form?
请注意使用:
<h:form id="form">
<!-- other content -->
<ui:include src="panel.xhtml" />
<!-- other content -->
</h:form>
<ui:include src="dialog.xhtml" />
Run Code Online (Sandbox Code Playgroud)
是不可接受的解决方案.
我使用的是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>
Run Code Online (Sandbox Code Playgroud)
分段:
<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>
Run Code Online (Sandbox Code Playgroud)
这会引起一些警告:
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
Run Code Online (Sandbox Code Playgroud)
因为恢复的组件不会在后续回发时重新删除RESTORE_VIEW。
对于我的实验来说,这些警告是无害的,可以安全地忽略。
不过,我打开了一个拉取请求以最终修复它。
| 归档时间: |
|
| 查看次数: |
10945 次 |
| 最近记录: |