以编程方式打开可关闭的对话框 [英] Primefaces open closable dialog programmatically
问题描述
我写了上面的代码:
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屋!