Re: how to loop Map model?

"Jonathan Revusky" <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
On Tue, Apr 8, 2008 at 3:42 PM, Zemian Deng <[email protected]> wrote:
> Hello,
>
> Have inserted a java.util.Properties into template scope, how do I loop over
> the map with all entries as key value pair?
>
> I tried something like this, and it got error:
>
> <#list Request.applicationProps as entry>
>                  <tr><td>${entry.key}</td><td>${entry.value}</td></tr>
>  </#list>

<#list Request.application.Props?keys as key>

<tr><td>${key}</td><td>${Request.applicationProps[key]}</td></tr>
</#list>

Actually, come to think of it, depending how FreeMarker is configured,
you might have to write this as:

<#list Request.application.Props?keys as key>
   <#if key?is_string>

<tr><td>${key}</td><td>${Request.applicationProps[key]}</td></tr>
  </#if>
</#list>

That's because (depending on the configuration) the map might return
the object's methods as part of the key set.

JR

> freemarker.template.TemplateException: Expected collection or sequence.
> Request.applicationProps evaluated instead to freemarker.template.SimpleHash
> on line 23, column 20 in WEB-INF/view/systeminfo.ftl.
>
>
>
> --
> Thanks,
> Zemian Deng
> -------------------------------------------------------------------------
>  This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
>  Register now and save $200. Hurry, offer ends at 11:59 p.m.,
>  Monday, April 7! Use priority code J8TLD2.
>
> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
> _______________________________________________
>  FreeMarker-user mailing list
>  [email protected]
>  https://lists.sourceforge.net/lists/listinfo/freemarker-user
>
>

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Register now and save $200. Hurry, offer ends at 11:59 p.m., 
Monday, April 7! Use priority code J8TLD2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.