• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

using EL to get the keySet of a HashMap

 
Rancher
Posts: 4804
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67749
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4804
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.

Following the idea, this works:

 
Bear Bibeault
Sheriff
Posts: 67749
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
If I had asked people what they wanted, they would have said faster horses - Ford. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic