Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launching JSF dialog conditionally

How can I launch a dialog according to some conditions? I am using primefaces components.

like image 499
Naveed S Avatar asked Dec 05 '22 19:12

Naveed S


2 Answers

With 3.x, RequestContext also provides an easier api called execute.

RequestContext.getCurrentInstance().execute("dialogue.show()");
like image 162
Cagatay Civici Avatar answered Dec 25 '22 14:12

Cagatay Civici


RequestContext provides a useful API to pass parameters from JSF backing beans in json format to ajax callbacks like oncomplete. Execute javascript from server side and add components to update programmatically.

An example of code for Backend Bean:

RequestContext context = RequestContext.getCurrentInstance();

if (condition)
{
    context.addCallbackParam("someVariable", true);
}
else
{
    context.addCallbackParam("someVariable", false);
}

We wand to write a javaScript function in the frontend (xhtml ) to handle this callback,like this

function precautionsDialogShow(xhr, status, args)
{
    if(args.someVariable)
    {
        dialogue.show();
    }
}
like image 45
Abin Manathoor Devasia Avatar answered Dec 25 '22 15:12

Abin Manathoor Devasia