Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update a component in parent window from a dialog of PrimeFaces Dialog Framework

I am using PF dialog framework to open a dialog.

public void addSpecFeatures(){
    genericFeatures = new GenericFeatures();
    Map<String,Object> options = new HashMap<String, Object>();
    options.put("resizable", false);
    options.put("draggable", false);
    options.put("modal", true);
    options.put("widgetVar", "featureDialog");
    RequestContext.getCurrentInstance().openDialog("PAGEName", options, null);
}

From the dialog I would like to update a component in the parent page. So, I tried below code

public void addFeatures(){
    if (null != genericFeatures && null != genericFeatures.getName()) {
        if (!genericFeaturesList.contains(genericFeatures)) {
            genericFeaturesList.add(genericFeatures);
            RequestContext context = RequestContext.getCurrentInstance();
            context.update("contentform:tabView:featureTable");
            context.closeDialog("PAGEName");
        }
    }
}

But code throws below exception:

Caused by: javax.faces.el.EvaluationException: org.primefaces.expression.ComponentNotFoundException: Cannot find component for expression "contentform:tabView:featureTable" referenced from "j_id1".

While in parent Window I am able update messages with below code

<p:commandLink id="create" update=":contentform:tabView:message" />

If we are using PF Dialog Framework and open it through Java code, does it mean that there is no Parent-Child relation with the opener window?

like image 917
Subodh Joshi Avatar asked Feb 09 '23 15:02

Subodh Joshi


1 Answers

With PrimeFaces Dialog Framework, dialogs are loaded as separate views in a HTML <iframe>.

In other words, the dialog has its own JSF component tree as well as its own HTML DOM tree which is independent from the page which opened the dialog. This is particularly useful for idempotent, bookmarkable and navigable dialogs.

However, your dialog appears to be not such one. It seems to still be interested in its opener and be dependent from it during the close. The solution is relatively simple: just don't let the dialog be interested in its opener. Let the opener itself be interested in the dialog close event which is available as dialogReturn event in <p:ajax> nested in the dialog opener button. See also Dialog Framework - Data showcase.

<h:form>
    ...
    <p:commandButton ... action="#{bean.showDialog}">
        <p:ajax event="dialogReturn" update=":foo:bar" />
    </p:commandButton>
</h:form>

The alternative is to use a normal <p:dialog> instead of PF Dialog Framework.

<h:form>
    ...
    <p:commandButton ... oncomplete="PF('dialog').show()" />
</h:form>
<p:dialog widgetVar="dialog">
    <h:form>
        ...
        <p:commandButton ... update=":foo:bar" oncomplete="PF('dialog').hide()" />
    </h:form>
</p:dialog>
like image 112
BalusC Avatar answered Feb 13 '23 16:02

BalusC