我正在使用PF对话框框架打开对话框。
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);
}
我想从对话框中更新父页面中的组件。所以,我尝试下面的代码
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");
}
}
}
但是代码抛出以下异常:
造成原因:javax.faces.el.EvaluationException:
org.primefaces.expression.ComponentNotFoundException:找不到
表达式“ contentform:tabView:featureTable”的组件被引用
来自“ j_id1”。
在父窗口中时,我可以使用以下代码更新消息
<p:commandLink id="create" update=":contentform:tabView:message" />
如果我们使用的是PF Dialog Framework并通过Java代码将其打开,这是否意味着打开程序窗口没有父子关系?
最佳答案
使用PrimeFaces对话框框架,对话框在HTML <iframe>
中作为单独的视图加载。
换句话说,该对话框具有其自己的JSF组件树以及其自己的HTML DOM树,该树与打开对话框的页面无关。这对于幂等,可书签和可导航对话框特别有用。
但是,您的对话框似乎不是这样。它似乎仍然对它的开启者感兴趣,并在关闭期间依赖于它。解决方案相对简单:只是不要让对话框对其打开器感兴趣。让打开器本身对对话框关闭事件感兴趣,该事件可以嵌套在对话框打开器按钮中的dialogReturn
中的<p:ajax>
事件中使用。另请参见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。<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>