从Managed Bean函数调用Primefaces对话框 [英] Calling Primefaces dialog box from Managed Bean function

查看:200
本文介绍了从Managed Bean函数调用Primefaces对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有某些功能的托管bean,根据该功能的某些条件,我想调用一个对话框

Hi I have a managed bean with some functions , based on some condition in that function I will like to call a dialog box

受管bean函数按原样

Managed bean function goes as

public String editStudent(){    
    setReadOnly(false);     
    setButton(true, true, true, false, true, true,true);
    LockItem lItem;
    if(selectStudent !=null){
        lItem = (LockItem) services.getbyId("LockItem", condition);
        if (lItem == null){
            System.out.println("Student Avalibale for process :::"); 
            studentRedirect();
            return "studentEdit.jsf?faces-redirect=true";
        } else {
             //To show dialog from here
             System.out.println("Student Not Avalibale : Locked By " + lItem.getLockedBy());
        }
    } else {
        FacesMessage msg;
        msg = new FacesMessage("Please select the record.");
        FacesContext.getCurrentInstance().addMessage(null, msg);
        return show("menu");
    }
}

有没有什么方法可以用来从此类托管函数调用对话框

Is there any method using which we can call the dialog box from such managed function

推荐答案

您可以使用 RequestContext (或 PrimeFaces (如果您使用的是6.2版或更高版本)类.

You can, by using the RequestContext (or PrimeFaces if you are using the version 6.2 or higher) class.

假设您具有以下条件:

<p:dialog id="myDialogID" widgetVar="myDialogVar">
....
</p:dialog>

因此,在facelet本身(即onclick=myDialogVar.show();)中进行操作的方式可以在托管bean中完成,如下所示:

So the way you do in the facelet itself, i.e. onclick=myDialogVar.show();, the same can be done in your managed bean like so:

对于PrimeFaces< = 3.x

RequestContext context = RequestContext.getCurrentInstance();
context.execute("myDialogVar.show();");

对于PrimeFaces> = 4.x到PrimeFaces< 6.2 (根据@dognose和@Sujan)

For PrimeFaces >= 4.x to PrimeFaces < 6.2 (as per @dognose and @Sujan)

RequestContext context = RequestContext.getCurrentInstance();
context.execute("PF('myDialogVar').show();");

对于PrimeFaces> = 6.2

PrimeFaces current = PrimeFaces.current();
current.executeScript("PF('myDialogVar').show();");

这用于使用目标对话框.如果您只需要显示一条消息而没有优先选择任何自定义对话框,则可以通过以下方式做到这一点:

This is for using targeted dialogs. If you just need to show a message without giving preference to any custom dialog, then you can do it this way:

FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Message Title", "Message body");

// For PrimeFaces < 6.2
RequestContext.getCurrentInstance().showMessageInDialog(message);

// For PrimeFaces >= 6.2
PrimeFaces.dialog().showMessageDynamic(message);

您可以传入参数并设置回调.请参阅链接中的展示示例.

You can pass in arguments and set callbacks as well. Refer to the showcase examples in the link.

另请参见:

这篇关于从Managed Bean函数调用Primefaces对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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