Reputation: 6647
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).
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.
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?
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?
Upvotes: 0
Views: 754
Reputation: 10720
I think the right way is
<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}" />
Upvotes: 1