我有这个片段:
<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>
但我未能成功尝试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" />
不是一个可以接受的解决方案。
我正在使用JSF 2.2.8(mojarra)和PF 5.1
答案 0 :(得分: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以最终修复它。
答案 1 :(得分:-3)
仅在对话框中使用一个表单。对我来说很好。
<h:body>
<h:form id="OneFormId">
<!-- Some content -->
</h:form>
<p:dialog id="MyDialogId" header="My Header Info"
widgetVar="MyWidgetVarName" modal="true" appendTo="@(body)">
<h:form id="MyFormId">
<p:outputPanel>
<p:messages id="MyMsgId" autoUpdate="true" />
<h:panelGrid columns="2">
<h:outputLabel for="usr" value="User:" />
<p:inputText id="usr" value="#{MyManageBeanName.MyProperty}"
required="true" requiredMessage="User is required." />
</h:panelGrid>
<p:separator />
<h:panelGrid columns="2">
<p:commandButton value="Save" id="MyBtnSaveId"
styleClass="ui-priority-primary" icon="ui-icon-circle-check"
process="@form" />
<p:commandButton value="Cancel" id="MyBtnCancelId"
onclick="PF('MyWidgetVarName').hide()"
styleClass="ui-priority-primary" icon="ui-icon-close"
process="MyBtnCancelId" />
</h:panelGrid>
</p:outputPanel>
</h:form>
</p:dialog>
<h:form id="OtherFormId">
<!-- Some content -->
</h:form>