Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

contains() always returning false  RSS feed

 
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.
 
Bartender
Posts: 20328
110
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.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!