Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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();
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}" />
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.