Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh the page after closing p:dialog

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?

like image 843
99maas Avatar asked Dec 11 '22 23:12

99maas


1 Answers

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.

like image 110
BalusC Avatar answered Jan 21 '23 10:01

BalusC