Primefaces Dialog Framework – 来自menuitem的dialogReturn事件

我在Table.xhtml中有一个primefaces p:datatable ,并且在我用于使用对话框框架打开对话框的同一页面上有一个p:commandbutton 。 与对话框相关的内容位于Dialog.xhtml 。 我正在为Table.xhtmlDialog.xhtml使用名为TableDialog.java的单个支持bean。 关闭对话框后, p:datatable中的值将相应地更新

 

Table.xhtml如下

      Table    

#{col}

这是Dialog.xhtml

      Dialog      

TableDialog.java包含以下代码

 import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; import javax.faces.context.FacesContext; import org.primefaces.context.RequestContext; @ManagedBean @SessionScoped public class TableDialog { public ArrayList resourceList=new ArrayList(); private String selected; String attributeValue = null; public TableDialog(){ this.resourceList.add("Black"); this.resourceList.add("White"); } public void updateValue(){ System.out.println("update value"); RequestContext context = RequestContext.getCurrentInstance(); Map options = new HashMap(); options.put("resizable", false); options.put("dynamic", true); options.put("height", 100); options.put("width", 300); options.put("contentHeight", 100); options.put("contentWidth", 250); context.openDialog("Dialog", options, null); } public void test(){ System.out.println("test"); } public void cancelValue(){ RequestContext context = RequestContext.getCurrentInstance(); context.closeDialog(this.attributeValue); System.out.println("cancel update resource attribute value"); this.attributeValue = null; System.out.println("this.attributevalue = " + this.attributeValue); } public void saveValue(){ RequestContext context = RequestContext.getCurrentInstance(); if (this.attributeValue == null) { System.out.println("No value"); context.execute("noValueDialog.show()"); return; } System.out.println("this.attributevalue = " + this.attributeValue); this.resourceList.add(this.attributeValue); this.attributeValue = null; context.update("form:resourceAttributeValueDataTable"); RequestContext.getCurrentInstance().update("form:resourceAttributeValueDataTable"); context.closeDialog(this.attributeValue); System.out.println("after hidden button execute " ); } public String getSelected() { return selected; } public void setSelected(String selected) { this.selected = selected; } public ArrayList getResourceList() { return resourceList; } public void setResourceList(ArrayList resourceList) { this.resourceList = resourceList; } public String getAttributeValue() { return attributeValue; } public void setAttributeValue(String attributeValue) { this.attributeValue = attributeValue; } } 

一切都很好。

我的问题是:

我想用p:contextMenu打开对话框。 p:menuitem正确打开对话框但是在关闭对话框后我无法更新p:dataTable 。 由于对话框架只支持p:commandButtonp:commandLink我无法使用

 

在里面p:menuitem 。 在互联网上搜索工作我在http://forum.primefaces.org/viewtopic.php?f=3&t=32131找到了解决方案。 它说

“目前,您可以执行以下操作来解决此问题:

  1. menuitem删除p:ajax
  2. 添加p:commandbutton xhtml并添加id =“…”和style =“display:none”
  3. 将onclick =“…”添加到menuitem以使用javascript触发> commandbutton的click()事件,并引用名称应为“formID:buttonID”的按钮。“

我是java,primefaces和ajax的新手,对javascript和jquery一无所知。 所以我无法弄清楚究竟要在onclick =“……..”内写什么。

 

这样每当我选择一个菜单项时,就会执行隐藏按钮。 任何帮助将受到高度赞赏。

我找到了如何在JavaScript中触发隐藏的JSF commandLink的解决方案?

Table.xhtml的更新版本包含

     #{col}         function triggerHiddenEvent() { document.getElementById("form:hiddenCommand").click(); }