5

I've the below dialog:

<h:form id="r1">
  <p:commandButton value="Basic" type="button" onclick="PF('dlg1').show();" />
  <p:dialog header="Basic Dialog" widgetVar="dlg1">
    <h:outputText id="test" value="Welcome to PrimeFaces" />
  </p:dialog>
</h:form>

How can I refresh the JSF page after closing the dialog?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
99maas
  • 1,239
  • 12
  • 34
  • 59
  • See here also: https://stackoverflow.com/a/11150042/1599699 `window.location.replace(window.location.href)` – Andrew Dec 21 '18 at 16:37

1 Answers1

15

The <p:dialog> supports the ajax close event. This only requires it being placed inside a <h:form> (on contrary to the general recommendation), so you need to make sure that it's already manually poisitioned to the very end of the <h:body> and that you don't make use of appendToBody.

<h:body>
    <h:panelGroup id="content" layout="block">
        ...
    </h:panelGroup>

    ...

    <h:form>
        <p:dialog>
            <p:ajax event="close" update=":content" />
            ...
        </p:dialog>
    </h:form>
</h:body>

Use if necessary update="@all" if you intend to update the entire page. But better is to update only the parts which really need to be updated.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555