velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Kienenberger <mkien...@alaska.net>
Subject Re: [FAQ] How do you check for null?
Date Fri, 03 Dec 2004 15:39:17 GMT
Shinobu Kawai <shinobu.kawai@gmail.com> wrote:
> Problem: I want to check for null, something like this:
>     #if ($car.fuel == null)
> 
> 
> Approach 1: Use the fact that null is evaluated as a false conditional.
>   cf. http://jakarta.apache.org/velocity/user-guide.html#Conditionals
>     #if( ! $car.fuel )
> 
> Note : The conditional will also pass if the result of $car.fuel is
> the boolean false.  What this approach is actually checking is whether the
> reference is null or false.
> 
> 
> Approach 2: Use the fact that null is quiet references.
>   cf. 
http://jakarta.apache.org/velocity/user-guide.html#Quiet%20Reference%20Notation
>     #if( "$!car.fuel" == "" )
> 
> Note : The conditional will also pass if the result of $car.fuel is a
> blank String.  What this approach is actually checking is whether the 
reference
> is null or blank.
> BTW, just checking for blank can be achieved by:
>     #if( "$car.fuel" == "" )

So you really either need to use the tool or do this:

#if ((! $car.fuel) && ("$!car.fuel" == ""))

-Mike


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Mime
View raw message