velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Barbara Baughman <baugh...@utdallas.edu>
Subject Re: null in velocity
Date Thu, 02 Dec 2004 20:34:21 GMT
If you are doing a test for java 'null' value, then
#if ($car.fuel)
will return true if $car.fuel is NOT a java null value.

If you are checking for an empty string, then use the String
comparison.

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

If you want to check for both:
#if ($!car.fuel=="")

I have a general purpose tool with a method that checks for null or
empty or all blanks and include the tool object in all Velocity
contexts.

#if ($tool.isEmpty($car.fuel))

You may have a different requirement that would require a special
method.  Perhaps you want it to return false if fuel is null or empty
or the value 0.  Then you would have to create your own method in the
$car object.

#if ($car.hasFuel())

BTW, always use '==' instead of '=' when making comparisons in
Velocity.

Barbara Baughman
X2157

On Thu, 2 Dec 2004, THE ULTIMATE SUBBIAH wrote:

> How to check for null in velocity
> for eg. I load a class in the context Class:: car
>
> #if ($car.getFuel() = null ?? )
>
> This does not work.
> Thx
>
> _________________________________________________________________
> The happening world of BPO! Know all that you need to know!
> http://www.bpowatchindia.com/msn/ Keep in step with what’s hot!
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
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