jsfprimefacesdialogview-scope

Will PrimeFaces Dialog Framework break view scope as compared to p:dialog?


I'm using PrimeFaces 5.

I would like to open a dialog when a button is pressed.

<p:commandButton value="add upload" actionListener="#{theForm.openUpload}" >

public void openUpload() {
    this.item = new Item();
    RequestContext.getCurrentInstance().openDialog("uploadForm");
}

There will be a save button in the dialog to save the inputs.

<h:commandButton value="#{text['button.add']}" id="add" styleClass="btn btn-default" actionListener="#{theForm.confirmAdd}"/>

public void confirmAdd() {
    RequestContext.getCurrentInstance().closeDialog("uploadForm");
}

My managed bean is @ViewScoped. Will the command button break the view scope if the dialog is in an external file as done by PrimeFaces Dialog Framework? Whenever I click the "add upload" button, the @PostConstruct method is called again just like the scope is lost.

Comments section of the official blog says it won't break the view scope, but here the forum a core developer says openDialog() creates a new view, therefore it breaks the view scope.

Can someone confirm this?


Solution

  • PrimeFaces' Dialog Framework basically shows another view in an <iframe> tag. I wouldn't call that breaking a view scope, but the dialog view will have it's own scope, because it is practically a different page. That may or may not be desirable in different circumstances. As PrimeFaces' User Guide says:

    Dialog Framework (DF) is used to open an external xhtml page in a dialog that is generated dynamically on runtime.

    p:dialog

    Dialog Framework

    My recommendation would be to use p:dialog by default. Only use Dialog Framework in cases like I mentioned in the last bullet point.