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

南楼画角 提交于 2021-02-07 07:55:57

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/33545435/update-a-component-in-parent-window-from-a-dialog-of-primefaces-dialog-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!