Can you do something like this in a velocity template?
#set ($map = $myobject.getMap() )
#foreach ($mapEntry in $map.entrySet())
<name>$mapEntry.key()</name>
<value>$mapEntry.value()</value>
#end
it outputs blank tags like so:
<name></name>
and
<value></value>
What am I doing wrong?
I'm looking for a way to loop through a HashMap in velocity, and this will work too.
Just like the way you would loop through a HashMap in java.
Your mistake is referring to key and value as methods (with trailing "()" parenthesis) instead of as properties. Try this:
In other words, use either a property, like mapEntry.key, or the method, like mapEntry.getKey().
To clarify (I cannot comment), in general you can use either the Java get methods, or replace them by the corresponding name without with a small letter and without
()
.So
$mapEntry.getKey()
ormap.key
.Here the Value
So , we need to iterate the group of value;
In the above code we can see check the value will be like -"data1,data2 etc ..." but after using the get(), we can able to get the instance value.