I want to open a global p:confirmDialog
based on a bean boolean value. I would like to have something like this:
<p:commandButton value="Save" actionListener="#{bean.save}"
update="@form" oncomplete="jsfunction();">
<p:confirm header="Confirm" message="Are you sure?" rendered="#{bean.boolean}"/>
</p:commandButton>
But rendered doesn't work there (I wish).
Also, I don't want to duplicate the p:commandButton
and use its rendered attribute to achieve this.
Is there any way to get this done without changing too many things? I have to do it in a lot of buttons.
One thing to try would be using your boolean value to render your
<p:confirmDialog>
If that does not work for you the only other way I see is the two
<p:commandButton>
option you are trying to avoid.It's a bit hacky, but you can use a JSTL "c:if" tag between your commandButton and the p:confirm tag. Because JSTL tags are interpreted earlier in the execution flow of a Facelet page, the p:confirm tag won't complain that its parent isn't a valid commandButton. For example:
I know that this question is a bit old, but I was recently having the same problem with conditional/dynamic confirmations and none of the above solutions worked fine for me.
After some tests, I built my button using the attribute disabled (introduced in PrimeFaces 6.0) as in:
You must use visible instead of rendered. the code will be like this :
if you need the dialog be shown oncomplete, set the dlgWgt.show() in the proper event.