JSF Expression Language Question (EL)

I have a menu item that I want to show / hide only if the user has certain roles.

I am using the rendered attribute for this, but I am stuck on something. It works...

rendered="#{loginHandler.hasStaffRole}" 

... But it is not...

 rendered="#{loginHandler.hasStaffRole or loginHandler.hasInstructorRole or loginHandler.hasVolunteerRole}" 

The error I get in Eclipse for one problem:

"cannot apply expression operators to method bindings"

Any idea how I should fix this?

+4
source share
2 answers

Answering my question. The problem was that the LoginHandler.hasStaffRole () method needed to declare LoginHandler.isHasStaffRole () in order to be recognized as a property. (In the end, I changed it to .isUserHasStaffRole.)

Thanks.

+8
source

I had the same problem: rendered="#{user.canEdit or user.isRole('ROLE_1', 'ROLE_2')}"

The "solution" for my Eclipse 4.3 was to cancel the arguments: rendered="#{user.isRole('ROLE_1', 'ROLE_2') or user.canEdit}"

Adding parentheses did not help. Your mileage may vary.

+1
source

Source: https://habr.com/ru/post/1339059/


All Articles