Vineeth NG
Vineeth NG

Reputation: 270

show dialog in PrimeFaces based on value in bean

I have a p:dialog which is displayed by oncomplete of a commandButton

<p:commandButton value="Update" id="update"
    actionListener="#{serviceTypeViewBean.beforeUpdate}"
    oncomplete="updatedlg.show();)">
</p:commandButton>

This dialog has a list which is updated in the 'beforeUpdate' method. I want to add a condition in the oncomplete that if the list is not empty show the dialog

if(list != empty){
 updatedlg.show()
};

How to add this condition in the oncomplete of commandButton?

Upvotes: 1

Views: 1486

Answers (2)

gadzix90
gadzix90

Reputation: 764

You can do it as @Xtreme Biker suggested. The other solution is to use callbackParam:

Add to your beforeUpdate method code like the following:

if(list != empty){
   RequestContext.getCurrentInstance().addCallbackParam("emptyList", false);
} else {
   RequestContext.getCurrentInstance().addCallbackParam("emptyList", true);
}

Then you can check the param in your oncomplete attribute like this:

<p:commandButton value="Update" id="update"
    actionListener="#{serviceTypeViewBean.beforeUpdate}"
    oncomplete="if(!args.emptyList) { PF('updatedlg').show(); }">
</p:commandButton>

Please notice that callbackParam is flexible and you can find usage for it in many cases.

Upvotes: 1

Aritz
Aritz

Reputation: 31679

You can use EL evaluation in order to render/hide javascript code:

oncomplete=#{not empty serviceTypeViewBean.list ? 'updatedlg.show()' : '' }

See also:

Upvotes: 0

Related Questions