velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Margus Kliimask <margus.kliim...@mindworks.ee>
Subject Testing for nulls with #if
Date Wed, 14 Oct 2009 10:35:00 GMT
Hi,
I've run into a problem with testing for a null in #defined block with
an #if directive. The manual states: "The variable $foo is evaluated
to determine whether it is true, which will happen under one of two
circumstances: <..> or (ii) the value is not null.

I feed an array of lists
...
String[] [] Items = {{"A", "100"}, {"B", null}};
context.put("Items", Items);
...

to this Velocity script:
...
#define( $key )$item.get(0)#end
#define( $val )$item.get(1)#end

#foreach ( $item in $Items )
(1)#if( $item.get(1) )$key:$val
#end
(2)#if( $val )$key:$val
#end

#end
...

I get back:
(1)A:100
(2)A:100

(1)(2)B:$item.get(1)

So, #if could detect null (missing value) in #if( $item.get(1) ), but
could not in #defined block #if( $val ). What am I missing? I
definitely don't want to mention the b-word here :) and appreciate any
help, guidance or comments.

Thanks,
Margus

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


Mime
View raw message