Primefaces以编程方式将对话框打开为对话框

时间:2018-08-25 13:33:22

标签: java jsf primefaces

我可以像这样的帖子以编程方式打开一个对话框:

Primefaces open closable dialog programmatically

我也可以在对话框中打开另一个对话框!但是当我想用这段代码关闭它时,它就不会关闭!

RequestContext.getCurrentInstance().closeDialog(null);

我什么都不能点击

只有当我打开两个对话框时,它才会发生

index.xhtml

<p:commandButton value="Open First Dialog" process="@form" update="@form" actionListener="#{mybean.openFirstDialog}"/>

mybean.java

@Component
@Scope("session")
public class MyBean{

 public void openFirstDialog() {
        RequestContext requestContext = RequestContext.getCurrentInstance();

        Map<String, Object> options = new HashMap<>();

        options.put("modal", true);
        options.put("width", "850");
        options.put("contentWidth", "520");
        options.put("closable", false);
        options.put("resizable", false);

        requestContext.openDialog("/page/firstdialog", options, null);
    }

}

firstdialog.xhtml

<p:commandButton value="Open Second Dialog" process="@form" update="@form" actionListener="#{firstDialogBean.openSecondDialog}"/>

FirstDialogBean.java

@Component
@Scope("view")
public class FirstDialogBean{

public void openSecondDialog() {
        RequestContext requestContext = RequestContext.getCurrentInstance();

        Map<String, Object> options = new HashMap<>();

        options.put("modal", true);
        options.put("width", "850");
        options.put("contentWidth", "520");
        options.put("closable", false);
        options.put("resizable", false);

        requestContext.openDialog("/page/seconddialog", options, null);
    }

}

seconddialog.xhtml

<p:commandButton value="Close Second Dialog" process="@form" update="@form" actionListener="#{secondDialogBean.close}"/>

secondDialogBean.java

@Component
@Scope("view")
public class SecondDialogBean{
public void close() {
        RequestContext.getCurrentInstance().closeDialog(null);
    }
}

实际上,我在关闭对话框时没有传递NULL!我做东西并传递一个对象!但我不能在这里写完整的代码 然后当我关闭第二个对话框时,我可以在第一个对话框中获取该对象,然后再次做一些事情

我希望我能说出我的意思

,然后单击“关闭第二个对话框”,它卡住了! 我也尝试过,但没用:

RequestContext.getCurrentInstance().closeDialog("/page/seconddialog");

1 个答案:

答案 0 :(得分:0)

您需要命名要关闭的对话框的名称...

RequestContext.getCurrentInstance().openDialog("titleEdit", options,
                null);

RequestContext.getCurrentInstance().closeDialog("titleEdit");

有关一次打开两个对话框以及如何关闭它们的信息,请参见this example