[stringtemplate-interest] string template arraylist iteration issue

Pradeep Vasudevan pradeep.v at cordic.com
Thu May 3 16:40:37 PDT 2012


Hi All,

repost of my ST issue (wrongly posted on antlr grp) Also updated my typo 
and stack trace from the prev post after
the replay from Terence Parr.

|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

|W/System.err(580):<string>  669:21: 'arr' came as a complete surprise to me
  no such template: /test
  passed 1 arg(s) to template null with 0 declared arg(s)
|

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, 
'$', '$');*


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20120504/6678d6f4/attachment.html 


More information about the stringtemplate-interest mailing list