Primefaces以编程方式打开可关闭对话框 [英] Primefaces open closable dialog programmatically

查看:25
本文介绍了Primefaces以编程方式打开可关闭对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从后台 bean 动态创建一个 primefaces 对话框.上面的代码我已经写好了:

I want to dynamically create a primefaces dialog from the backing bean. I have written the code above:

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 页面中:我有

and in my jsf page: i have

 <h:form id="form1" >
        <h:commandButton value="show Dialog" action="#{createDialog.showDialog()}" />

 </h:form>

问题是当我将它设置为可见时,我得到了对话框,但我无法关闭(我没有得到关闭图标,也无法拖动它)!

The problem is that when i set it to visible , i got the dialog but neither i can close (i don't get the close icon nor i can drag it)!

推荐答案

你需要替换这一行:

requestContext.openDialog("widget");

到那个:

requestContext.execute("PF('widget').show()");     

RequestContext.openDialog() 方法引用Primefaces Dialog Framework API,与p:dialog 组件不同.

RequestContext.openDialog() method reffers to Primefaces Dialog Framework API which is different to p:dialog component.

来自 primefaces 用户指南:

From primefaces user guide:

Dialog Framework (DF) 用于打开外部 xhtml 页面在运行时动态生成的对话框.

Dialog Framework (DF) is used to open an external xhtml page in a dialog that is generated dynamically on runtime.

因此,RequestContext.openDialog() 希望您提供 xhtml 页面的路径作为参数.

So, RequestContext.openDialog() expects you to provide path to xhtml page as argument.

并且 p:dialog 组件有 javascript api show() 和 hide() 方法与之交互.

And p:dialog component have javascript api show() and hide() methods to interact with it.

这篇关于Primefaces以编程方式打开可关闭对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆