• Post Reply Bookmark Topic Watch Topic
  • New Topic

EL expression not working as expected for Map

 
Ben Ooms
Ranch Hand
Posts: 47
Debian Eclipse IDE Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I'm starting to work with JSF and stumble into an issue with resolving a Map value even my friend Google cannot answer ;<).

This is the context:

Having an object:

In my backing bean:

In my facelet (the map is filled with values) I try to access the property prop from one of the A object and get a null :


So my question is:
Am I not allowed to chain and access the property in this way and is there a way to work around this?

 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try
 
Ben Ooms
Ranch Hand
Posts: 47
Debian Eclipse IDE Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Please be sure to post JSF questions in the JSF forum. I have moved this post there for you.


Sorry, Didn't see that

Thanks
 
Ben Ooms
Ranch Hand
Posts: 47
Debian Eclipse IDE Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
E Armitage wrote:Try


Well tried this as well without succes. Strange thing is that when I changed the Map to a List does work.
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a difefrence between map["0"] and map[0].
Maps are not indexed so map[0] doesn't really make sense. map["0"] accesses a record in the map whose key is the String "0".
 
Ben Ooms
Ranch Hand
Posts: 47
Debian Eclipse IDE Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
E Armitage wrote:There is a difefrence between map["0"] and map[0].
Maps are not indexed so map[0] doesn't really make sense. map["0"] accesses a record in the map whose key is the String "0".


You are absolutly right but i'm not trying to access by index but by key value of type Long.

Sorry for my newbee jsf question but does this mean that given a Map<Long,SomeObject> I never be able to access a value in that map because the key is parsed by the EL as string and therefore cannot find my value?
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EL does work with Long keys (not Integer) so map[0] should work if the map has a key with a value of 0L.
 
Tim Holloway
Bartender
Posts: 18412
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup.


Would be the proper notation here to get the value for key 0. Although attempting to use basic classes as backing beans can often be a problem, so a better alternative would be a:


Where "map" is a propery of "myBean".

Note that you cannot use a map as the value of a sequential construct such as h:dataTable or ui:repeat, since Map has no natural order. You would have to use an ordered collection such as SortedMap.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!