Primefaces 5.0, JSF 2.2, Wildfly 8.1
The following use case:
- Click a command button in a view (with some parameters)
- The bean method looks something up in the database - if necessary dialog1 is shown. In dialog1 there is a form and a command button.
- The command button in dialog1 is clicked, the bean method looks something up in the database.
- Dialog1 is closed and dialog2, depending on the result of the bean method, is shown.
bean1.java:
public void buttonClicked() {
Map<String, Object> options = new HashMap<>();
options.put("modal", true);
options.put("widgetVar", "dialog1");
options.put("id", "dlg1");
if(somethingTrue()) {
RequestContext.getCurrentInstance().openDialog("dialog1.xhtml", options, null);
}
}
Everything fine. Dialog1 shows up.
dialog1.xhtml:
<h:body>
<h:form>
<p:commandButton value="Button" actionListener="#{bean2.dialog1ButtonClicked}" />
</h:form>
</h:body>
bean2.java:
public void dialog1ButtonClicked() {
Map<String, Object> options = new HashMap<>();
options.put("modal", true);
options.put("widgetVar", "dialog2");
options.put("id", "dlg2");
if(somethingTrue()) {
RequestContext.getCurrentInstance().openDialog("dialog2.xhtml", options, null);
}
}
dialog2.xhtml:
<h:body>
The operation was successful.
</h:body>
Dialog2 shows up within dialog1!
How can I close dialog1 and show dialog2 NOT within dialog1?
I tried closing dialog1 with Primefaces Dialog Framework before opening dialog2:
RequestContext.getCurrentInstance().closeDialog(null);
RequestContext.getCurrentInstance().openDialog("dialog2.xhtml", options, null);
Dialog2 doesn't show up.
I tried opening dialog2 after the AJAX callback <p:ajax event="dialogReturn" listener="#{bean1.dialogClosed}"/>
Dialog2 doesn't show.
I tried the client side Java Script call: onclick="PF('dialog1').hide()"
Dialog2 still shows up nested into dialog1.
Solution:
RequestContext.getCurrentInstance().openDialog("dialog1.xhtml", options, null);
dialog1.xhtml:
The dialog bean:
Another bean for the dialog closing:
The method closeRegistration removes the viewscoped bean. Therefore another call of the the dialog within the same page will start the dialog flow from the beginning.
we can close on dialog in
onsuccess
oronerror
oroncomplete
also. Check the image for your referenceusing
onHide
you can open another dialog like this.It also work when close dialog using escape key.