1
votes

I show a Primefaces Dialog using the dialog framework, in this way:

RequestContext.getCurrentInstance().openDialog("myDialog", options, params);

In the page myDialog.xhtml I have a message and two buttons: YES or NO. I would like to close the Pf dialog with the event "onclick", is there a way the to do this?

I cannot statically define the dialog using p:dialog and than close it using PF('widgetVarName').hide();

1

1 Answers

2
votes

Generally, you may want something like this:

<p:commandButton action="#{someBean.closeDialog('yes')}" process="@form" update="@form"
    icon="#{icons.yes}" value="#{bundle.yes}" />

<p:commandButton action="#{someBean.closeDialog('no')}" process="@form" update="@form"
    icon="#{icons.no}" value="#{bundle.no}" />


public void closeDialog(String choice)
{
    RequestContext requestContext = RequestContext.getCurrentInstance();

    Object someData = executeChoice(choice);

    requestContext.closeDialog(someData);
}

Otherwise, if you really need to close the dialog on onclick (sounds a little strange...) you may use:

<p:remoteCommand name="closeDialog" action="#{someBean.closeDialog}" process="@this" />

<p:commandButton type="button" onclick="closeDialog()" icon="#{icons.close}" 
    value="#{bundle.close}" />


public void closeDialog()
{
    RequestContext requestContext = RequestContext.getCurrentInstance();

    requestContext.closeDialog(null);
}

Finally, if you need a pure javascript solution, you may want:

<p:commandButton type="button" 
    onclick="PrimeFaces.closeDialog({pfdlgcid:'#{param.pfdlgcid}'})" 
    icon="#{icons.close}" value="#{bundle.close}" />