This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JSF and the fly likes contains() always returning false Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "contains() always returning false" Watch "contains() always returning false" New topic
Author

contains() always returning false

M Sham
Greenhorn

Joined: Oct 18, 2012
Posts: 1
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

Joined: Jun 25, 2001
Posts: 14487
    
    7

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: contains() always returning false
 
Similar Threads
List of common elements
Sticky nested lists problem in Struts 2
How to get the request parameters while the enctype is multipart/form-data
htmldatatable displays stale values?
comparing two ArrayLists