File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Accessing value in MAP using EL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Accessing value in MAP using EL" Watch "Accessing value in MAP using EL" New topic
Author

Accessing value in MAP using EL

Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
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
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Check this piece of code...


JDBCSupport - An easy to use, light-weight JDBC framework -
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60781
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing value in MAP using EL
 
Similar Threads
Enumerated type toString()
EL expression
My Study Notes !!!
JSP Coding Conventions/Best Practices
Color Parameter