[stringtemplate-interest] Have you ever subclassed StringTemplate or StringTemplateGroup?

Terence Parr parrt at cs.usfca.edu
Fri Nov 18 14:11:29 PST 2005


On Nov 18, 2005, at 5:40 AM, Micheal J wrote:

> Doesn't look like there is ever a need to do so. I can't think of a
> compelling use case in fact. Anyone else?

Yeah, I suppose you could override to fix a bug or something too.

> Also, how would the AttributeRenderer abstraction handle the  
> situation where
> I need to display two date values in the same view (i.e. template)  
> but with
> different formats?.

It doesn't handle this situation well at all, I'm afraid.  This would  
normally be rare unless you are doing something like "In Polish, the  
date is xxx but in English we use this format yyy".  In that case,  
you can just pass in a wrapper object per date that indicates it's  
value.  In my view, displaying a Date is so complicated in logic that  
you cannot display it w/o testing values etc..., which is forbidden  
in ST to avoid logic in the template.  I think it's proper to ask  
Date.toString() or a wrapper to do the formatting

> Is this a good case for per-attribute AttributeRenderer  
> registrations at the
> StringTemplate level?

I'd probably go with

st.setAttribute("date", new PolishDateRenderer(aDate));

just to use the existing mechanism.  That object could even be reused.

Ter


More information about the stringtemplate-interest mailing list