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

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

问题描述

我想从支持bean动态创建一个原始对话框。
我写了上面的代码:

  public void showDialog(){
UIComponent panelGroup = facesContext.getViewRoot()。findComponent(form1);
System.out.println(found or not ??+ panelGroup.toString());
对话框对话框= 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 Dialogaction =#{createDialog.showDialog()}/>

< / h:form>

问题是当我将其设置为可见时,我得到了对话框,但我都不能关闭我没有收到关闭的图标,我也不能拖动它)!

解决方案

你需要替换这行:

  requestContext.openDialog(widget); 

  requestContext.execute( PF( '工具')显示()。); 

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



从原点用户指南:


对话框(DF)用于在运行时动态生成的
对话框中打开一个外部xhtml页面。


所以,RequestContext.openDialog()期望你提供xhtml页面的路径作为参数。



和p:对话框组件具有javascript api show()和hide()方法与之交互。


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");
}

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)!

解决方案

You need to replace this line:

requestContext.openDialog("widget");

to that:

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

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

From primefaces user guide:

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

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

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

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

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