2014-10-28 55 views
5

我有这样的片段:PrimeFaces内p嵌套形式:与appendTo =“@(身体)对话框

<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> 

,但我没有成功尝试的processupdate一些组合为button1产生过程什么... input1甚至重置...

那么,如何建立一个p:dialog,可以在一个片段或复合材料组件内运输,并从外部排除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(钻嘴鱼科)和PF 5.1

+0

我想不接受开始包含并结束? :)对我来说,无论如何你都会得到嵌套的表格 – 2014-10-28 18:39:14

+0

不,不允许:)但是我不想避免嵌套表格,我试图让它们在appendTo属性的帮助下工作。根据PF对话文档,这应该是可能的。 – 2014-10-29 01:34:58

+0

但是不是嵌套形式是什么给你带来麻烦?我总是期望它会通过appendTo在输出的html中不起作用。在primefaces论坛上有一些关于它的讨论,也许你可以在那里找到一些东西 – 2014-10-29 05:40:29

回答

0

最后,我发现使用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来最终修复它。

-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> 

+3

你读过这个问题了吗? – 2015-09-23 15:36:57