Search code examples
primefacesjsf-2jsf-2.2

Primefaces close modal without hide dialog


I working with primefaces 6.2 on JavaEE 8 .
I have a basic dialog with a commandbutton created a modal over that .(Sory for bad english !)
I want to close modal without closing basic dialog .
How can fix this problem ?


<p:dialog header="Basic Dialog" id="user-management" widgetVar="user-management" width="700px" height="300px" resizable="false">
        <p:toolbar>
            <f:facet name="left">
                <p:commandButton type="button" title="Add" icon="ui-icon-plus" onclick="PF('userDialog').show();"/>
            </f:facet>
        </p:toolbar>
        <p:spacer/>
        <p:dataTable value="#{userGroupBean.userSet}" var="user">
            // Show user information
        </p:dataTable>
    </p:dialog>

    <p:dialog header="User"     
              widgetVar="userDialog"
              closeOnEscape="true"
              resizable="true"
              modal="true"
              showEffect="fade"
              hideEffect="fade"
              height="auto"
              width="auto">
        <h:panelGrid columns="2">
          // Some inputs ...
        </h:panelGrid>
        <p:spacer/>
        <div class="dialog-footer">
            <p:commandButton value="Save"
                             oncomplete="PF('userDialog').hide();"
                             process="@form"
                             update="user-management"
                             action="#{userGroupBean.save}"/>
        </div>
    </p:dialog>     

Solution

  • The basic dialog is not 'closed' it is updated via update="user-management" and hence the html that is returned from the server is put in the html dom in with the dialog in the default state: closed. You have several options:

    • Don't update the dialog but update it's contents (my prefered solution) by adding e.g. a panel inside it and update that
    • Set a flag in a beanand use visible="#{mybean.dialogIsVisibleFlag}"
    • in the oncomplete of the ajax call do a PF('user-management').show()