You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Doug Brower <db...@inphonic.com> on 2004/03/19 16:34:11 UTC

[Newbie] Setting a boolean

Hi, This seems like a ridiculous question but I'm stumped. The following code results in the TRUE branch being taken, but I'm expecting the value of $myBool to be false. What am I doing wrong?

#set( $myBool = "false" )
#if( $myBool  )
myBool is true!<br/>
#else
myBool is false<br/>
#end

Thanks!

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


Re: [Newbie] Setting a boolean

Posted by Barbara Baughman <ba...@utdallas.edu>.
Lose the quotes around false to define a Boolean value.  You are
defining $myBool as a String instead of a Boolean.  As a String,
Velocity checks ($myBool) to see if it is defined in the Velocity
context and is not null.  Since it is defined and has the non-null
value "false", it evaluates to true.

The following also works, leaving $myBool as a String:
#if ($myBool=="true")
(returns boolean false).

Barbara Baughman
X2157

On Fri, 19 Mar 2004, Doug Brower wrote:

> Hi, This seems like a ridiculous question but I'm stumped. The following code results in the TRUE branch being taken, but I'm expecting the value of $myBool to be false. What am I doing wrong?
>
> #set( $myBool = "false" )
> #if( $myBool  )
> myBool is true!<br/>
> #else
> myBool is false<br/>
> #end
>
> Thanks!
>
> ---------------------------------------------------------------------
> 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: [Newbie] Setting a boolean

Posted by SainTiss <sa...@gmx.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I'm just guessing here, but could it be that $myBool is actually a Boolean 
(Object) instead of a primitive type?

In that case, chances are you get "true" because the Object is not null.
To access the boolean value, I'd guess you'd have to do #if 
($myBool.booleanValue())

Cheers,

Hans

On Friday 19 March 2004 16:34, Doug Brower wrote:
> Hi, This seems like a ridiculous question but I'm stumped. The following
> code results in the TRUE branch being taken, but I'm expecting the value of
> $myBool to be false. What am I doing wrong?
>
> #set( $myBool = "false" )
> #if( $myBool  )
> myBool is true!<br/>
> #else
> myBool is false<br/>
> #end
>
> Thanks!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org

- -- 
Ark Linux - Linux for the Masses (http://arklinux.org)

Capitalism: 
You don't have any cows. The bank will not lend you money to buy cows, 
because you don't have any cows to put up as collateral.

Representative Democracy:
You have two cows. Your neighbors pick someone to tell you who gets the milk. 

In a world without walls and fences, who needs windows and gates?

Hans Schippers
2LIC INF
UA 2003-2004
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFAWxivXlnUYIbmLOQRAjOmAKChhJ4evD50/2TN1+ZdvxQB4+WlJACdGLnv
W1R/Zda6m2XgQbPkotrT7FY=
=UMTe
-----END PGP SIGNATURE-----


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


Re: [Newbie] Setting a boolean

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Mar 19, 2004, at 10:34 AM, Doug Brower wrote:

> Hi, This seems like a ridiculous question but I'm stumped. The 
> following code results in the TRUE branch being taken, but I'm 
> expecting the value of $myBool to be false. What am I doing wrong?
>

You are setting $myBool to a string, and this it's not boolean false.

A reference is false if either it's Boolean.FALSE or null

> #set( $myBool = "false" )
> #if( $myBool  )
> myBool is true!<br/>
> #else
> myBool is false<br/>
> #end
>
> Thanks!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


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