varsha varsha - 3 months ago 25
Java Question

How to retrieve hashmap values in velocity template

How to retrieve values from the following hashmap in velocity template? Please help..

LinkedHashMap<String, LinkedHashMap<Integer, Object>> hashmap = new LinkedHashMap<String, LinkedHashMap<Integer,Object>>();

Answer

First, add the hashmap to your backing Java class (reference here).

context.put("myhashmap", hashmap);

Then you can reference anywhere in your Velocity template, e.g:

<span>$myhashmap.get("foo").get(1).toString()</span>
Comments