• 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Accessing value in MAP using EL

 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have some queries regarding EL when values is being accessed using Map..

For expression

${colorMap[red]} then method invoked is colorMap.get(pageContext.findAttribute("red"))

and for ${colorMap["red"]} method invoked is colorMap.get("red").

You access a map's values through its keys, which you can specify with the [] operator,
for example, ${colorMap[red]} and ${colorMap["red"]}. The former specifies an IDENTIFIER for the key, whereas the latter specifies a STRING. For the identifier, the PageContext.findAttribute method searches all FOUR JSP scopes (searching the page, request, session, and application scopes) for a scoped variable with the name that you specify, in this case, red. On the other hand, if you specify a string, it's passed directly to the map's get method..


In the explanation given above in bold. Does it mean that the use of second expression will not find in any of the scope for the corrospoding value of red. In either case it ultimately finds the values of KEY red. Then what is difference with both the method invoked?

Thanks in Advance.

Jay
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this piece of code...

 
Marshal
Posts: 67418
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scope search only happened for variables in order to evaluate their value. The value of string literals are the value of that literal, so there's no need to evaluate it.
 
Hey cool! They got a blimp! But I have a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic