从 PrimeFaces 对话框框架的对话框更新 parent window 中的组件
Update a component in parent window from a dialog of PrimeFaces Dialog Framework
我正在使用 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);
}
我想从对话框中更新 parent 页面中的组件。所以,我尝试了下面的代码
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");
}
}
}
但是代码抛出以下异常:
Caused by: javax.faces.el.EvaluationException:
org.primefaces.expression.ComponentNotFoundException: Cannot find
component for expression "contentform:tabView:featureTable" referenced
from "j_id1".
在 parent Window 期间,我可以使用以下代码更新消息
<p:commandLink id="create" update=":contentform:tabView:message" />
如果我们使用的是PF Dialog Framework,通过Java代码打开,是不是和openerwindow没有Parent-Child关系?
使用 PrimeFaces 对话框框架,对话框在 HTML <iframe>
.
中作为单独的视图加载
换句话说,对话框有它自己的 JSF 组件树以及它自己的 HTML DOM 树,它独立于打开对话框的页面。这对于幂等、可添加书签和可导航的对话框特别有用。
但是,您的对话似乎不是这样的。它似乎仍然对其开场价感兴趣,并在收盘时依赖于它。解决方案相对简单:只是不要让对话框对其开启者感兴趣。让打开器本身对对话框关闭事件感兴趣,该事件可作为嵌套在对话框打开器按钮中的 <p:ajax>
中的 dialogReturn
事件使用。另见 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 对话框框架。
<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>
我正在使用 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);
}
我想从对话框中更新 parent 页面中的组件。所以,我尝试了下面的代码
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");
}
}
}
但是代码抛出以下异常:
Caused by: javax.faces.el.EvaluationException: org.primefaces.expression.ComponentNotFoundException: Cannot find component for expression "contentform:tabView:featureTable" referenced from "j_id1".
在 parent Window 期间,我可以使用以下代码更新消息
<p:commandLink id="create" update=":contentform:tabView:message" />
如果我们使用的是PF Dialog Framework,通过Java代码打开,是不是和openerwindow没有Parent-Child关系?
使用 PrimeFaces 对话框框架,对话框在 HTML <iframe>
.
换句话说,对话框有它自己的 JSF 组件树以及它自己的 HTML DOM 树,它独立于打开对话框的页面。这对于幂等、可添加书签和可导航的对话框特别有用。
但是,您的对话似乎不是这样的。它似乎仍然对其开场价感兴趣,并在收盘时依赖于它。解决方案相对简单:只是不要让对话框对其开启者感兴趣。让打开器本身对对话框关闭事件感兴趣,该事件可作为嵌套在对话框打开器按钮中的 <p:ajax>
中的 dialogReturn
事件使用。另见 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 对话框框架。
<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>