jsf - PrimeFaces Dialog + appendToBody=true 不起作用

标签 jsf jsf-2 primefaces facelets

我正在使用 PF 3.5 和 JSF Mojarra 2.1。

我有一个对话框,我想使用 appendToBody=true。不过,这通常会导致“不可预测的行为”。

基本上对话框的作用是,当我从数据表中选择一个条目(一个 persn 实体)时,它会为我提供可以编辑的填充输入框,从而编辑特定条目(人员详细信息)。

有时输入框会正确填充条目数据。有时他们不这样做。
appendToBody=false 不会发生此行为。
除此之外,我很确定没有嵌套表单。

正如您会注意到的,我正在尝试使用纯 ajax 导航的“单页设计”。

主页 (index.xhtml)

<h:body>

    <pe:layout id="page" fullPage="true">

        <!-- North -->
        <pe:layoutPane id="north" position="north" minSize="140"
            closable="true" resizable="false">
            ....
        </pe:layoutPane>

        <!-- West -->
        <pe:layoutPane id="west" position="west" minWidth="150" size="180"
            style="font-size: 14px !important;" closable="true"
            styleClassHeader="menuBar" resizable="false">
            <f:facet name="header">Main Menu</f:facet>

            <h:form id="form1">

                <p:panelMenu id="panelMenu" style="width: 160px !important">

                    <!-- On menu click update with Ajax centerpanel and msgPanel -->
                    <p:submenu label="Persons" style="font-size: 10px ">

                        <p:menuitem value="Person List" update=":centerpanel"
                            actionListener="#{layout.setAll('formPersonList.xhtml', 'Person List')}"
                            action="#{person.init()}">
                        </p:menuitem>

                    </p:submenu>

                    .....

                </p:panelMenu>
            </h:form>
        </pe:layoutPane>

        <!-- Center -->
        <pe:layoutPane id="content" position="center"
            style="font-size: 14px !important" styleClassHeader="menuBar">

            <h:panelGroup id="centerpanel" layout="block">
                <ui:include id="include" src="#{layout.navigation}" />

            </h:panelGroup>

        </pe:layoutPane>
    </pe:layout>

该对话框位于文件 formPersonList.xhtml 中并且位于表单之外
<ui:composition ....> 

      <h:form id="mainForm">
            <p:contextMenu for="personTable">

                <p:menuitem value="View Details" 
                            process="@form" actionListener="#{person.handleSelectedPerson()}"
                            update=":dlgPersonGrp"
                            oncomplete="dlgPerson.show();">
                </p:menuitem>

            </p:contextMenu>

        <p:dataTable id="personTable ....>
            ....person entities
        </p:dataTable>

      </h:form>

    <p:dialog   widgetVar="dlgPerson" showEffect="size"
                width="1100"  appendToBody="true">

                <h:panelGroup id="dlgPersonGrp">
                    <ui:include src="formPerson.xhtml" />
                </h:panelGroup>

     </p:dialog>
</ui:composition>

最后,带有输入框的表单:formPerson.xhtml
<ui:composition ....> 

      <h:form id ="subForm">
                ....Input boxes that are supposed to be filled up from a backing bean 
                    and then resubmitted to edit the chosen entry


      </h:form>

</ui:composition>

我试图尽可能地把它弄糊涂。如果您需要更多详细信息,请告诉我。

最佳答案

我知道这是一个老问题,但我在使用 Primefaces 5 时遇到了同样的问题。
解决方案很简单,我在标签中包含了属性 appendTo="@(body)"。

<p:dialog header="Title" widgetVar="dlg" modal="true" appendTo="@(body)">
  <h:outputText value="Dialog text..." />
  <p:commandButton value="Ok" onclick="PF('dlg').close()" />
</p:dialog>

关于jsf - PrimeFaces Dialog + appendToBody=true 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18607921/

相关文章:

jsf-2 - 使用空字符串参数调用 EL 方法接收空字符串

java - 从代码中获取 SelectOneMenu 的所选项目

java - 丰富的动态分页 :dataTable/rich:datascroller with large datasets

javascript - 每当您返回使用 javascript 或 jsf 的页面时,如何在 jsp 页面上维护复选框状态,而不将其存储到数据库中

java - 带有可编辑数据表的 Primefaces selectManyCheckbox 将空值提交给转换器

jsf-2 - dataTable 内 JSF 复合组件的唯一 ID

jsf - IBM AppScan - 加密 session (SSL) Cookie 中缺少安全属性

jsf - 使用 p :graphicImage in a tagfile 显示 BLOB 图像

java - 如何从 JSF 连接到 SQL Server

ajax - 在 ajax 事件上禁用/启用命令按钮