You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Manish <pr...@gmx.net> on 2004/10/06 08:53:39 UTC

Compare null

How can I compare 'null' in my velocity template for if condition???
The following results in an error.

#if(null == $p.getDisplayaddressbool()){
}

TIA,
- Manish


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


Re: Compare null

Posted by Nathan Bubna <na...@esha.com>.
Manish said:
> Ah thanks!
> This should work, but there a global macro somewhere in my code that
> replaces all these blank "" for nulls by NA value.
> Now I'll have to figure out whether this test comes first or it is the
> macro. Someone else wrote this code and he's leaving....

heh.  yeah, that's always fun.

> It's fun being a programmer, excitement never stops!!!!! ;)
>
> - Manish
>
> p.s.
> Nathan,
> Are you one of the original developers of Velocity? I find your replies
> quite useful and thorough.

nope.  i'm not even a committer for the velocity core.  i'm just a
velocity-tools committer and long-time velocity user (getting close to 4
years).  so i've been around the lists and the code long enough to pick up a
few useful tricks and tips. :)

Nathan Bubna
nathan@esha.com

>
> ----- Original Message -----
> From: "Nathan Bubna" <na...@esha.com>
> To: "Velocity Users List" <ve...@jakarta.apache.org>
> Sent: Wednesday, October 06, 2004 12:43 PM
> Subject: Re: Compare null
>
>
> > Manish said:
> > > How can I compare 'null' in my velocity template for if condition???
> > > The following results in an error.
> > >
> > > #if(null == $p.getDisplayaddressbool()){
> > > }
> >
> > you're confusing java with VTL.  VTL has no null keyword or token. (though
> it
> > was discussed favorably in ages long past.)
> >
> > i've found the most reliable way to test for nulls is:
> >
> > #if( "$!myboolean" == "" ) foo is null! #end
> >
> > Nathan Bubna
> > nathan@esha.com
> >
> >
> > ---------------------------------------------------------------------
> > 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
>


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


Re: Compare null

Posted by Manish <pr...@gmx.net>.
Ah thanks!
This should work, but there a global macro somewhere in my code that
replaces all these blank "" for nulls by NA value.
Now I'll have to figure out whether this test comes first or it is the
macro. Someone else wrote this code and he's leaving....
It's fun being a programmer, excitement never stops!!!!! ;)

- Manish

p.s.
Nathan,
Are you one of the original developers of Velocity? I find your replies
quite useful and thorough.


----- Original Message -----
From: "Nathan Bubna" <na...@esha.com>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Wednesday, October 06, 2004 12:43 PM
Subject: Re: Compare null


> Manish said:
> > How can I compare 'null' in my velocity template for if condition???
> > The following results in an error.
> >
> > #if(null == $p.getDisplayaddressbool()){
> > }
>
> you're confusing java with VTL.  VTL has no null keyword or token. (though
it
> was discussed favorably in ages long past.)
>
> i've found the most reliable way to test for nulls is:
>
> #if( "$!myboolean" == "" ) foo is null! #end
>
> Nathan Bubna
> nathan@esha.com
>
>
> ---------------------------------------------------------------------
> 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


Re: Compare null

Posted by Nathan Bubna <na...@esha.com>.
Manish said:
> How can I compare 'null' in my velocity template for if condition???
> The following results in an error.
>
> #if(null == $p.getDisplayaddressbool()){
> }

you're confusing java with VTL.  VTL has no null keyword or token. (though it
was discussed favorably in ages long past.)

i've found the most reliable way to test for nulls is:

#if( "$!myboolean" == "" ) foo is null! #end

Nathan Bubna
nathan@esha.com


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


Re: Compare null

Posted by Manish <pr...@gmx.net>.
I want to different things on "null" and "false" so this solution won't help
much.
Thanks anyway!

- Manish

----- Original Message -----
From: "Kalyani Kale" <ka...@ascindia.com>
To: "'Velocity Users List'" <ve...@jakarta.apache.org>
Sent: Wednesday, October 06, 2004 12:51 PM
Subject: RE: Compare null


> #set ( $displayAddr = $p.getDisplayaddressbool())
>
> if($displayAddr)
> //if displayAddr is not null
> #else
> //control will come here if displayAddr is null #end
>
> If the above code is inside a for loop, the u'll have to set $displayAddr
to
> false at the end of the loop.
>
> #set ( $displayAddr = false )
>
>
> Kalyani
>
> -----Original Message-----
> From: Manish [mailto:prolist@gmx.net]
> Sent: Wednesday, October 06, 2004 12:24 PM
> To: Velocity Users List
> Subject: Compare null
>
> How can I compare 'null' in my velocity template for if condition???
> The following results in an error.
>
> #if(null == $p.getDisplayaddressbool()){
> }
>
> TIA,
> - Manish
>
>
> ---------------------------------------------------------------------
> 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
>


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


RE: Compare null

Posted by Kalyani Kale <ka...@ascindia.com>.
#set ( $displayAddr = $p.getDisplayaddressbool())

if($displayAddr)
	//if displayAddr is not null
#else
	//control will come here if displayAddr is null #end

If the above code is inside a for loop, the u'll have to set $displayAddr to
false at the end of the loop.

#set ( $displayAddr = false )


Kalyani

-----Original Message-----
From: Manish [mailto:prolist@gmx.net] 
Sent: Wednesday, October 06, 2004 12:24 PM
To: Velocity Users List
Subject: Compare null

How can I compare 'null' in my velocity template for if condition???
The following results in an error.

#if(null == $p.getDisplayaddressbool()){
}

TIA,
- Manish


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