ST AttributeRenderer ignores format option in template def
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jeff_Stroup
Posted On:   Monday, November 26, 2007 01:18 PM

Now that my grammar is working I'm running into problems with StringTemplate. Specifically I created an attribute renderer by implementing AttributeRenderer and registering it with the template group. public class BasicFormatRenderer implements AttributeRenderer { public String toString(Object o) { return o.toString(); } public String toString(Object o, String formatName) { if (formatName.equals("toUpper")) { return o.toString().toUpperCase(); } else if (formatName.equals("toLower")) { return o.toString().toLowerCase(); } else { throw new IllegalArgumentException("Unsupported format name"); } } }    More>>

Now that my grammar is working I'm running into problems with StringTemplate. Specifically I created an attribute renderer by implementing AttributeRenderer and registering it with the template group.

public class BasicFormatRenderer implements AttributeRenderer
{
public String toString(Object o) {
return o.toString();
}
public String toString(Object o, String formatName) {
if (formatName.equals("toUpper")) {
return o.toString().toUpperCase();
} else if (formatName.equals("toLower")) {
return o.toString().toLowerCase();
} else {
throw new IllegalArgumentException("Unsupported format name");
}
}
}



I reference it from an attribute in a template definition as follows.


tblName(x) ::= < <

Table name is $x;format="toUpper"$

>>


But instead of calling the version of toString with the formatName, it always calls the one with a lone string argument. This is somewhat encouraging but it's not what the ST Object Rendering example says should happen. How do I get it to call the correct version of toString?

Thanks,

Jeff

   <<Less
About | Sitemap | Contact