The first is iterating maps. Without going into too much detail, you may expect to be able to do the following:
<#list map as entry> Hi there ${entry.key}, this is your value ${entry.value} </#list>but you can't.
Neither can you do:
<#list map.entrySet() as entry> ... </#list>
Neither can you do:
<#list map.keySet() as key> ${map[key]} or ${map.key} or ${map.(key)} or ${map.[key]} </#list>
Instead, you need to do the following:
Neither can you do:
<#list map?keys as key> ${map.values[key_index]} </#list>Nice.
Yeah.
Thanks a lot . It helps me and solved my problem.... :)
ReplyDeleteThank you, safes me some time to figure this out myself.
ReplyDeleteOne simple note, the "Neither can you do:" title on the last code section seems to be a copy&paste error :-)
Actually, in Java the performance is better if you iterate over the entry set instead of the key set. For example, the following will work in Freemarker:
ReplyDelete<#list map.entrySet() as entry>
<input type="hidden" name="${entry.key}" value="${entry.value}" />
</#list>
I didn't get working the entrySet() version with Java.
DeleteIf 'map.values' doesn't work try 'map?values', like:
ReplyDelete<#list map?keys as key>
${map?values[key_index]}
Freemarker: 2.3.20
ReplyDeleteJava: 1.7 or higher
Data model: TreeMap()
Right solution: see "Anonymous 17 January 2013 at 05:41" comment
Thank you!