从PrimeFaces Dialog Framework的对话框更新父窗口中的组件
•浏览 1
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);
}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");
}
}
}<p:commandLink id="create" update=":contentform:tabView:message" /><h:form>
...
<p:commandButton ... action="#{bean.showDialog}">
<p:ajax event="dialogReturn" update=":foo:bar" />
</p:commandButton>
</h:form><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>
从对话框中我想更新父页面中的组件。所以,我尝试了下面的代码
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");
}
}
}<p:commandLink id="create" update=":contentform:tabView:message" /><h:form>
...
<p:commandButton ... action="#{bean.showDialog}">
<p:ajax event="dialogReturn" update=":foo:bar" />
</p:commandButton>
</h:form><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>
但代码抛出异常:
Caused by: javax.faces.el.EvaluationException:
org.primefaces.expression.ComponentNotFoundException: Cannot find
component for expression"contentform:tabView:featureTable" referenced
from"j_id1".
在父窗口中,我可以使用以下代码更新消息
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");
}
}
}<p:commandLink id="create" update=":contentform:tabView:message" /><h:form>
...
<p:commandButton ... action="#{bean.showDialog}">
<p:ajax event="dialogReturn" update=":foo:bar" />
</p:commandButton>
</h:form><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 Dialog Framework,通过Java代码打开,是不是意味着打开的窗口没有父子关系?
使用 PrimeFaces 对话框框架,对话框作为单独的视图加载到 HTML <iframe>.
换句话说,对话框有它自己的 JSF 组件树以及它自己的独立于打开对话框的页面的 HTML DOM 树。这对于幂等、可书签和可导航的对话框特别有用。
但是,您的对话框似乎不是这样的。它似乎仍然对它的开场白感兴趣,并在收盘时依赖它。解决方案相对简单:只是不要让对话框对其开启者感兴趣。让打开器本身对对话框关闭事件感兴趣,该事件可用作嵌套在对话框打开器按钮中的 <p:ajax> 中的 dialogReturn 事件。另请参阅对话框框架 - 数据展示。
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");
}
}
}<p:commandLink id="create" update=":contentform:tabView:message" /><h:form>
...
<p:commandButton ... action="#{bean.showDialog}">
<p:ajax event="dialogReturn" update=":foo:bar" />
</p:commandButton>
</h:form><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>
替代方法是使用普通的 <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);
}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");
}
}
}<p:commandLink id="create" update=":contentform:tabView:message" /><h:form>
...
<p:commandButton ... action="#{bean.showDialog}">
<p:ajax event="dialogReturn" update=":foo:bar" />
</p:commandButton>
</h:form><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>