我想从支持 bean 动态创建一个 primefaces 对话框。
我已经写了上面的代码:
public void showDialog(){
UIComponent panelGroup = facesContext.getViewRoot().findComponent("form1");
System.out.println("found or not??"+ panelGroup.toString());
Dialog dialog = new Dialog();
dialog.setId("sample");
dialog.setWidgetVar("widget");
dialog.setHeader("Sample");
dialog.setVisible(true);
dialog.setMinimizable(true);
dialog.setDynamic(true);
dialog.setHideEffect("fade");
dialog.setFooter("footer");
dialog.setDraggable(true);
dialog.setMinWidth(600);
dialog.setClosable(true);
dialog.setModal(true);
dialog.setAppendToBody(false);
panelGroup.getChildren().add(dialog);
RequestContext requestContext = RequestContext.getCurrentInstance();
requestContext.openDialog("widget");
requestContext.update("form1");
}
在我的 jsf 页面中:我有
<h:form id="form1" >
<h:commandButton value="show Dialog" action="#{createDialog.showDialog()}" />
</h:form>
问题是,当我将它设置为可见时,我得到了对话框,但我无法关闭(我没有关闭图标,也无法拖动它)!
最佳答案
您需要替换此行:
requestContext.openDialog("widget");
对此:
requestContext.execute("PF('widget').show()");
RequestContext.openDialog() 方法引用 Primefaces Dialog Framework API,它不同于 p:dialog 组件。
来自primefaces用户指南:
Dialog Framework (DF) is used to open an external xhtml page in a dialog that is generated dynamically on runtime.
因此, RequestContext.openDialog() 期望您提供 xhtml 页面的路径作为参数。
并且 p:dialog 组件有 javascript api show() 和 hide() 方法与之交互。
关于Primefaces 以编程方式打开可关闭对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24821590/