PrimeFaces Dialog + appendToBody=true not working
Asked Answered
A

2

4

I'm using PF 3.5 and JSF Mojarra 2.1.

I have a dialog which I want to use appendToBody=true. This usually results in "unpredictable behavior" though.

Basically what the dialog does is, when I choose an entry (a persn entity) from a datatable, it gives me filled up input boxes which I can edit, thus editing the particular entry (person details).

Sometimes the input boxes get filled up properly with the entries data. Sometimes they dont. This behavior does not happen with appendToBody=false. Aside from that I'm pretty sure there are no nested forms.

As you will notice I am trying out a "One page design" with purely ajax navigation.

Main page (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>

The dialog is in a file formPersonList.xhtml and is outside the form

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

Finally, the form with the input boxes: 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>

I have tried to dumb it down as much as possible. Let me know if you need more detail.

Audwen answered 4/9, 2013 at 7:32 Comment(3)
You have no form for your dialog. This is first big red light.Absorbing
The form is in formPerson.xhtml which is included inside the dialog (the last code section). It is the id = "subForm". I assume that works as the dialog form, unless it should also be outside the panelgroup.Audwen
But you have appendToBody="true", so you need a form. Anyway, something is not in order with the code you have posted, because you would have form in form, which is illegal and will not function.Absorbing
S
3

I know this is a old question, but I was having the same problem with Primefaces 5. The solution was simple, I've included the attribute appendTo="@(body)" in tag.

<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>
Stinnett answered 5/9, 2014 at 22:54 Comment(1)
What means the @ on this context?Apples
U
2

Perhaps the answer is not to use appendToBody. Do you really need it?

One of the common reasons for using appendToBody is to avoid error resulting from putting modal dialogs inside layouts. This workaround, as you've already noted, results in "unpredictable behaviour". The better way would be just to place the dialog outside the layout.

For more details please see:

Uranus answered 16/10, 2013 at 18:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.