有条件地使用p:confirm打开全局p:confirmDialog [英] Conditionally open global p:confirmDialog with p:confirm
问题描述
我想基于以下内容打开一个全局 p:confirmDialog
Bean布尔值.我想要这样的东西:
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).
此外,我不想复制p:commandButton
并使用其呈现的属性来实现这一目标.
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.
推荐答案
我知道这个问题有点老了,但是我最近在条件/动态确认方面遇到了同样的问题,上述解决方案都不适合我
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.
经过一些测试,我使用禁用属性(在PrimeFaces 6.0中引入)构建了按钮,如下所示:
After some tests, I built my button using the attribute disabled (introduced in PrimeFaces 6.0) as in:
<p:confirmDialog global="true">
<p:commandButton value="Yes" type="button" />
<p:commandButton value="No" type="button" />
</p:confirmDialog>
<p:commandButton actionListener="#{myBean.myMethod} value="Submit">
<p:confirm header="Confirmation" message="Are you sure?" disabled="#{myBean.boolean}"/>
</p:commandButton>
这篇关于有条件地使用p:confirm打开全局p:confirmDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!