Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Get Key from Map at particular index using OGNL

 
kiran chirravuru
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to get Key at particular index using OGNL in struts2
 
Ruth Mills
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This works for me, e.g. if I have a Map called "myMap" and want to get the key at index 0 from the map, then I can do something like this...

<s:hidden name="whatever" value="%{myMap.keySet().toArray()[0]}"/>

So in the OGNL, I have to call keySet() and then toArray() and can then just use an index in square brackets after that.

Hope that works for you too
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!