Ayrad Ayrad - 1 year ago 93
Java Question

in velocity can you iterate through a java hashmap's entry set()?

Can you do something like this in a velocity template?

#set ($map = $myobject.getMap() )
#foreach ($mapEntry in $map.entrySet())

it outputs blank tags like so:




What am I doing wrong?

Answer Source

Your mistake is referring to key and value as methods (with trailing "()" parenthesis) instead of as properties. Try this:

#set ($map = $myobject.getMap() )
#foreach ($mapEntry in $map.entrySet())

In other words, use either a property, like mapEntry.key, or the method, like mapEntry.getKey().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download