0

heres my test in java

public class person
{
    public String name;
    public int age;
    public String getName() { return name; }
    public int getAge() { return age; }
}

In my function I create a number of person objects and add it into an list

ArrayList<person> arr = new ArrayList<person>()
arr.add(person1);
arr.add(person2); etc etc

in the string template group file I have got

test(arr) ::= <<
 <table>
 $arr: {a|
 <tr><td>$a.name$</td><td>$a.age$</td></tr>
 }$
 </table>
>>

this is called from my list template

list (arr) ::= <<

$test(arr)$

... and other page details etc
>>

in version4 for I get template not found message with some stack trace as follows

Caused by: java.lang.ClassCastException: java.util.ArrayList
at org.antlr.runtime.tree.RewriteRuleTokenStream.nextNode(RewriteRuleTokenStream.java:58)
at org.stringtemplate.v4.compiler.STParser.subtemplate(STParser.java:1563)
at org.stringtemplate.v4.compiler.STParser.mapTemplateRef(STParser.java:3692)

but I can list an array as follows and it prints the object representation in string format (also I can use a map - ie key value pairs works ok too)

in string template

test(arr) :: =<<
 <p>
 $arr; seperator="</br>"$
 </p>
>>

how do we iterate list of object to print field values using string template grop in V4 am I using it in a wrong format/syntax?

any help/points would be greateful

note: we set $ as delimiter using new STGroupString("", templateGroup, '$', '$');

pvee
  • 25
  • 1
  • 5
  • kind of working now (not tested everything. tested with a string array with curly brackets ) seems its not a bug in stringtemplate .. its antlr - not sure where is this problem come from we are using antlr 3.4..runtime. but when me rolled back to the version 3.2 it worked. – pvee May 04 '12 at 12:00

1 Answers1

2

You are missing the terminating $ on your expression: $a.age should be $a.age$

Terence Parr
  • 5,912
  • 26
  • 32
  • Thanks, I missed a $ when I typed my question into stackoverflow. edited it now. still cant load the template (see edited question) – pvee May 03 '12 at 23:32