Naveed S
Naveed S

Reputation: 5266

Launching JSF dialog conditionally

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

Upvotes: 4

Views: 3519

Answers (2)

Abin Manathoor Devasia
Abin Manathoor Devasia

Reputation: 1973

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

Upvotes: 6

Cagatay Civici
Cagatay Civici

Reputation: 6504

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

RequestContext.getCurrentInstance().execute("dialogue.show()");

Upvotes: 10

Related Questions