从PrimeFaces对话框框架的对话框更新父窗口中的组件 [英] Update a component in parent window from a dialog of PrimeFaces Dialog Framework

查看:103
本文介绍了从PrimeFaces对话框框架的对话框更新父窗口中的组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PF对话框框架打开对话框.

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:

由以下原因引起:javax.faces.el.E​​valuationException: org.primefaces.expression.ComponentNotFoundException:找不到 表达式"contentform:tabView:featureTable"的组件被引用 来自"j_id1".

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" />

如果我们使用PF Dialog Framework并通过Java代码打开它,这是否意味着打开程序窗口没有父子关系?

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?

推荐答案

使用PrimeFaces对话框框架,对话框将作为单独的视图加载到HTML <iframe>中.

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

换句话说,该对话框具有自己的JSF组件树以及自己的HTML DOM树,该树与打开对话框的页面无关.这对于幂等,可书签和可导航对话框特别有用.

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.

但是,您的对话框似乎不是这样.它似乎仍然对它的开启者感兴趣,并在关闭过程中依赖于它.解决方案相对简单:只是不要让对话框对其打开器感兴趣.让打开器本身对对话框关闭事件感兴趣,该事件可以嵌套在对话框打开器按钮中的<p:ajax>中的dialogReturn事件中使用.另请参见对话框框架-数据展示柜.

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>

替代方法是使用普通的<p:dialog>代替PF Dialog Framework.

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>

这篇关于从PrimeFaces对话框框架的对话框更新父窗口中的组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆