Re: Can't get hashes to work
Brian Pontarelli <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
I went back through our previous thread and found that using the
${bean.coolMap(key)} syntax works. This is systemic based on how FM handles
the [] notation right?
-bp
On Wed, Jun 17, 2009 at 1:19 PM, Brian Pontarelli <[email protected]>wrote:
> So, I have been working on converting everything over to use BeansWrapper,
> but now I can't seem to get my hashes to work at all, even with
> DefaultObjectWrapper. I'm assuming this is something simple, but I can't
> figure it out. Here is my simple bean:
>
> public class Bean {
> public Map<Integer, String> coolMap = new HashMap<Integer, String>();
> private int age;
>
> public int getAge() {
> return age;
> }
>
> public void setAge(int age) {
> this.age = age;
> }
> }
>
>
> Here's the code that I'm using to execute the template:
>
> BeansWrapper ow = new BeansWrapper();
> ow.setExposeFields(true);
> ow.setSimpleMapWrapper(true);
>
> Bean bean = new Bean();
> bean.coolMap.put(1, "test");
> bean.setAge(42);
>
> Map<String, Object> context = new HashMap<String, Object>();
> context.put("bean", bean);
>
> Template template =
> freeMarkerConfiguration.getTemplate(templateName, locale);
> template.setObjectWrapper(ow);
> template.process(root, writer);
>
>
> The template is pretty simple:
>
> [#ftl/]
> Bean [#list bean.coolMap?keys as key]${key} ${bean.coolMap[key]}
> [/#list] ${bean.age}
>
>
> The error I'm getting is just the standard "Expected number, sequence, or
> string. bean.coolMap evaluated instead to
> freemarker.ext.beans.SimpleMapModel". It is failing at the
> ${bean.coolMap[key]} statement. However, that should work fine, right?
>
> -bp
>
>
>
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
FreeMarker-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freemarker-user