问题描述
我的页面上有两个Primefaces p:dialogs
,我有两个按钮来显示它们(一个是删除按钮,另一个是编辑按钮).
I have two Primefaces p:dialogs
in my page and I have two buttons to display them (the one is a delete button, the other one is an edit button).
我将对话框的可见属性设置如下:visible="#{fn:length(bean.selectedItems) gt 0}
用于删除按钮,而visible="#{fn:length(bean.selectedItems) eq 1}
,因此我可以删除多个元素,但只能同时编辑一个.
I set the visible attribute of the dialogs as follows: visible="#{fn:length(bean.selectedItems) gt 0}
for the delete button and visible="#{fn:length(bean.selectedItems) eq 1}
, so I can delete multiple elements, but only edit one at the same time.
现在,该bean是ViewScoped,因此,如果恰好选择了一项,并且有一个没有按下ajax提交的commandButton,则将显示两个对话框,这显然不是我想要的.
Now the bean is ViewScoped, so if there is exactly one item selected, and there is a commandButton without ajax submit pressed, both of the dialogs are displayed, which obviously is not what I want.
仅在需要时才显示适当对话框的最简单方法是什么?
What is the easiest way to show the appropriate dialog only when needed?
我不想为此设置额外的bean属性,因此让我们考虑一个简单的解决方案.还有另一种方法吗?也许将动作名称设置为视图范围参数?还是使用呈现的属性并通过javascript回调管理显示/隐藏?
I don't want to set an extra bean attribute for that, so let's consider that a trivial solution. Is there another way? Maybe setting the name of the action to a view scoped parameter? Or using the rendered attributes and managing the show/hide from javascript callback?
推荐答案
我认为正确的方法是
<p:commandButton value="DELETE"
onclick="deleteDialog.show()"
disabled="#{fn:length(bean.selectedItems) eq 0}" />
<p:commandButton value="EDIT"
onclick="editDialog.show()"
disabled="#{fn:length(bean.selectedItems) ne 1}" />
这篇关于JSF-有条件地显示两个对话框之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!