[stringtemplate-interest] Distinguish null and false in condition

Terence Parr parrt at cs.usfca.edu
Mon Sep 25 11:01:24 PDT 2006


On Sep 21, 2006, at 1:47 AM, Oliver Flege wrote:

> Hi,
>
> recently, I used ST to render xml tags; for tags that contained a  
> Boolean
> value, I had to distinguish between a null value (output <tag  
> xsi:nil="true"/>)
> and either true or false (output <tag>true</tag> / <tag>false</tag>)
>
> Since ST's if condition evaluates to false for both null and  
> Boolean.FALSE,
> I modified ST to support $if(?attr)$, which evaluates to true iff
> attr is not null.
>
> The changes necessary to support this are rather trivial (treat ?  
> similar to
> the ! operator and call chunk.testAttributeDefined(a) if ? is used,
> that funtion returns true iff a is not null).
>
> How about including this change in ST?

Hi!  An uncommon need I'd say...probably doens't warrant new syntax.   
Can you send in wrapped/tweaked booleans?  Easy with a subclass,  
override setAttribute.

Ter



More information about the stringtemplate-interest mailing list