[stringtemplate-interest] Maps vs aggregates vs beans
Steven Byrnes
erewhon at flatland.org
Wed Jul 26 17:42:18 PDT 2006
Hi,
I'm running into a problem with aggregates and multi-valued attributes. Not sure if it's lack of
understanding on my part or something else... I'm running String Template 2.3b7.
For the following template:
StringTemplate t = new StringTemplate("$name:{ <b>$it.a$ - $it.b$</b> }$");
if I use 1 or more aggregate attribute calls, it works, e.g.:
t.setAttribute("name.{a,b}", "foo", "blah");
t.setAttribute("name.{a,b}", "bar", "brap");
same thing for a simple bean. One or more setAttributes() will work.
t.setAttribute("name", new data("foo", "bar")); // where data() has getA() and getB() methods
If I use setAttribute() for multiple Hashmaps, it works. But if I only use one, I get an error, e.g.:
HashMap<String,String> m = new HashMap<String,String>();
m.put("a", "foo"); m.put("b", "blah");
t.setAttribute("name", m);
System.out.println(t.toString());
=>
Class java.lang.String has no such attribute: a in template context [anonymous anonymous]
java.lang.NoSuchFieldException: a
at java.lang.Class.getField(Class.java:1507)
at org.antlr.stringtemplate.language.ASTExpr.rawGetObjectProperty(ASTExpr.java:410)
at org.antlr.stringtemplate.language.ASTExpr.getObjectProperty(ASTExpr.java:314)
....
Any ideas?
Thanks,
Steven
More information about the stringtemplate-interest
mailing list