Reputation: 157
I have a Primefaces datatable.
<p:dataTable id="updateStaffTable" var="staff" value="#{staffBean.staffs}"
selection="#{staffBean.selectedStaff}" selectionMode="single"
paginator="true" lazy="true" styleClass="dataTableSize" rows="10" >
<p:ajax event="rowSelect" listener="#{staffBean.onRowSelect}"
update=":updateStaffForm:updateStaffPanelGrid" oncomplete="PF('updateStaffDialog').show()" />
</p:dataTable>
Now, I want to disable selection attribute if the user is not permitted. I can check the user's permissions programmaticly. I also have a bean to check that but I can't use rendered attribute here. How can I do that or is there any other good approach in order to do that?
Upvotes: 0
Views: 436
Reputation: 1108557
Just use EL in the attribute the usual way like as you did for other attributes. You can use the conditional operator ?:
to perform an if-else in EL.
E.g. set to single
only when user has the role ADMIN
:
selectionMode="#{request.isUserInRole('ADMIN') ? 'single' : null}"
As to the other answer suggesting binding
for this, it is not recommended to use binding
whenever the functionality is just possible purely in the view side. You can even just do selectionMode="#{bean.selectionMode}"
if you really need to control it from the bean on. Try to avoid binding
on a backing bean property as much as possible unless you need to dynamically populate components which for some unclear reason can't be done in view side (with JSTL you can do a lot).
Upvotes: 3