wood burning stoves 2.0*
The moose likes JSP and the fly likes using EL to get the keySet of a HashMap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "using EL to get the keySet of a HashMap" Watch "using EL to get the keySet of a HashMap" New topic
Author

using EL to get the keySet of a HashMap

Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

I have a HashMap that when I store it to the Session, and ask EL to display it, it works great.
Thus ${yearlycits} converts to this:

{1989=[4799156_1989-01-17], 1998=[5715314_1998-02-03, 5724424_1998-03-03], 1999=[5960411_1999-09-28, 5987140_1999-11-16]}

As you can see, the keys are Long, and the value is a list of String. You can notice, if you look closely, that the keys are not consecutive, they are really just

{1989, 1998, 1999}

What I want to do is get the keySet so I can then do a for-loop for each key value, get the list of Strings, and process them.

${yearlycits.keySet}

the view .jsp blows up:

org.apache.jasper.JasperException: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)

What am I doing wrong? I think I'm approaching it incorrectly.

Thanks
Pat
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

You can iterate over the Map and each iteration will be an instance of Map.Entry from which you can get they key and the value.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

Thanks.

Following the idea, this works:

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using EL to get the keySet of a HashMap