This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using EL to get the keySet of a HashMap

 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

Following the idea, this works:

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic