aspose file tools*
The moose likes JSP and the fly likes EL (${intKey}) is not working with Map<Integer,String>  ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "EL (${intKey}) is not working with Map<Integer,String>  ?" Watch "EL (${intKey}) is not working with Map<Integer,String>  ?" New topic
Author

EL (${intKey}) is not working with Map<Integer,String> ?

Sagar Vyas
Greenhorn

Joined: Feb 17, 2013
Posts: 10
Hello,

This is my first post in Coderanch and very excited to learn lots of new things.

I have one doubt related to EL (expression language).

I have created a map as below.

Map<Integer,String> map = new LinkedHashMap<Integer,String>();
map.put(2, "my value");

when I tried to access an element in my jsp as below I wont be able to get it.

${map[2]}

Then, I have found somewhere that ,it is taking as Long so it wont work.

but here my question is then how do I access integer key with EL ?

What is a way to access it ?

Looking for some help.

Thanks in advance,
Sagar Vyas


Sagar Vyas
"More Sharing and More Learning"
Bill Clar
Ranch Hand

Joined: Sep 21, 2006
Posts: 152

How are you setting the map attribute in the request object (HttpServletRequest)?

Are you using the name "map"?
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
The problem is that EL interprets your literal number as a Long.

So it would translate into java code loosely as:


Because Integer with a value of 2 is NOT equal to a Long with a value of 2 (different classes are never equal) the value fails to be retrieved from the map.

I don't know of any way in EL to not interpret literal numbers as Long.

Sagar Vyas
Greenhorn

Joined: Feb 17, 2013
Posts: 10
Bill Clar wrote:How are you setting the map attribute in the request object (HttpServletRequest)?

Are you using the name "map"?



Hi Bill,

Thanks for prompt reply,

It is not a case that I am using map, I kept name "map" just for example.

Thanks,
Sagar Vyas
Sagar Vyas
Greenhorn

Joined: Feb 17, 2013
Posts: 10
Stefan Evans wrote:
Because Integer with a value of 2 is NOT equal to a Long with a value of 2 (different classes are never equal) the value fails to be retrieved from the map.

I don't know of any way in EL to not interpret literal numbers as Long.



Hi Stefan,

Thanks for explanations,

That means is there not any way to access map value having integer key ? in EL ?

Thanks,
Sagar Vyas
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EL (${intKey}) is not working with Map<Integer,String> ?