velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Barbara Baughman <>
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

#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

#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

Barbara Baughman

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!
> Keep in step with what’s hot!
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message