Can't get hashes to work
Brian Pontarelli <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
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