• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

contains() always returning false

 
M Sham
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to redo how a website handles permission access to elements. Right now we have it so when someone logs in (ActiveUser) they have an ArrayList of Integers corresponding to the FunctionIDs they are permitted access to. For example when I log in I have the values 1, 2, 6, 7 in my ActiveUser.permissions List.

The problem is that I'm trying to render elements in JSF using <h:tag rendered="#{activeUser.permissions.contains(x)}"> for elements. This is always returning false regardless of the values in the List. I have verified that the value is in fact in my List using Debugging mode.

Also, if I replace #{activeUser.permissions.contains(1)} with #{activeUser.permissions.get(0) == 1} it works and the element renders. I know that .contains(<literal int>) works for java.lang.Integers, so I have the feeling this has something to do with JSF.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17989
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first question is: do you actually need View-side logic here? Putting logic in VIews is something you should not do unless there's no simpler choice. Among the reasons for that is that you run into problems like the one you have.

If your function choices can be displayed in tabular form, for example, a cleaner way to do it is to house them in a dataTable and build a corresponding DataModel that only contains the elements for the allowed functions. That can all be done within the backing bean and you won't have to get into fights with EL or View-side logic.

Otherwise, I can't really tell what's wrong with ""#{activeUser.permissions.contains(x)}"" because I don't know what datatype "x" is supposed to be or where "x" is coming from.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic