[stringtemplate-interest] Default Null Option
Terence Parr
parrt at cs.usfca.edu
Tue Sep 1 12:53:43 PDT 2009
On Aug 28, 2009, at 2:40 PM, Rene Villeneuve wrote:
> Hi guys,
>
> I am not sure if it’s the right place to ask my question, but I
> could not find a forum anywhere on the site.
>
> I just started to use string template and while I was able to get
> everything set up and working, I hit a little snag earlier today. In
> essence, all I’m trying to do is to ensure that every time there is
> a null value, instead of skipping it will format correctly with an
> empty value. While I can do it through the template, I want to do it
> programmatically to ensure that it’s always there, as I am not the
> only one developing templates. I got it working by creating an
> anonymous class, extending StringTemplate, that got an overridden
> parseAction in which I modified the list of option coming from
> parse.action by adding null every time.
>
How about subclassing ST and overriding setAttribute to wrap all null
values and replace null list elements with an Empty obj or something?
> I also had to modify the way the parser was working to make sure it
> would spawn sub template with the valid overwritten parseAction
> method. Now it’s working, but I am sure I am not using the right
> method. There must be a simpler way to add a default option that
> will be applied to every element in the template, I just cannot find
> it. Any form of help would be appreciated.
>
Your solution is clever :) might try the setAttribute though.
T
More information about the stringtemplate-interest
mailing list