File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Get  Key from Map at particular index using OGNL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Get  Key from Map at particular index using OGNL " Watch "Get  Key from Map at particular index using OGNL " New topic
Author

Get Key from Map at particular index using OGNL

kiran chirravuru
Greenhorn

Joined: Nov 25, 2009
Posts: 26
How to get Key at particular index using OGNL in struts2
Ruth Mills
Greenhorn

Joined: Apr 30, 2011
Posts: 1
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Get Key from Map at particular index using OGNL