• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EL expression not working as expected for Map

 
Ranch Hand
Posts: 47
Netbeans IDE Eclipse IDE Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try
 
Ben Ooms
Ranch Hand
Posts: 47
Netbeans IDE Eclipse IDE Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Eclipse IDE Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Eclipse IDE Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic