You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Mike Kienenberger <mk...@alaska.net> on 2004/10/27 01:02:20 UTC
#set $var = (boolean exp) ==> $var = null
I suppose in retrospect since Velocity is String-oriented, this behavior is
to be expected, but it sure seems counter-intuitive that
#set ($listHasElements = ($list.size() > 0))
#if ($listHasElements)
for lists containing elements does not work, but
#if ($list.size() > 0)
does.
Maybe my pointing this out will save someone else some pain.
-Mike
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: #set $var = (boolean exp) ==> $var = null
Posted by Mike Kienenberger <mk...@alaska.net>.
Shinobu Kawai <sh...@gmail.com> wrote:
> Well, here's what you /can/ do using 1.3:
>
> #set ($listIsEmpty = $list.empty)
> #if ($listIsEmpty)
> no elements!
> #else
> first element : $list.get(0)
> #end
>
> It looks like it's the expression that Velocity doesn't like, and not
> the Boolean. (It didn't work for ... = !$list.empty)
Thanks for looking into it.
Fortunately, out of my hundreds of templates, I only used that construct
once, and it was trivial to place it directly in the #if statement.
I never thought to check $list.empty, but that's a variable assignment, not
a velocity boolean expression.
Probably the best news is that it's fixed in 1.4.
-Mike
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: #set $var = (boolean exp) ==> $var = null
Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Mike,
> > #set ($listHasElements = ($list.size() > 0))
> > $listHasElements
> >
> > should show "$listHasElements", right? But it was "true". It worked
> > for both 1.4 and CVS HEAD.
> >
> > Maybe there's something wrong with your "$list".
>
> Nope, but maybe the behavior changed in 1.4. I'm using 1.3.1.
Yeah, I tried it on 1.3 and it failed. ;)
Well, here's what you /can/ do using 1.3:
#set ($listIsEmpty = $list.empty)
#if ($listIsEmpty)
no elements!
#else
first element : $list.get(0)
#end
It looks like it's the expression that Velocity doesn't like, and not
the Boolean. (It didn't work for ... = !$list.empty)
Best regards,
-- Shinobu Kawai
--
Shinobu Kawai <sh...@gmail.com>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: #set $var = (boolean exp) ==> $var = null
Posted by Mike Kienenberger <mk...@alaska.net>.
Shinobu Kawai <sh...@gmail.com> wrote:
> Hi Mike,
>
> > I suppose in retrospect since Velocity is String-oriented, this behavior
is
> > to be expected, but it sure seems counter-intuitive that
> >
> > #set ($listHasElements = ($list.size() > 0))
> >
> > #if ($listHasElements)
> >
> > for lists containing elements does not work, but
> >
> > #if ($list.size() > 0)
> >
> > does.
> I wonder why it works in my environment?
>
> #set ($listHasElements = ($list.size() > 0))
> $listHasElements
>
> should show "$listHasElements", right? But it was "true". It worked
> for both 1.4 and CVS HEAD.
>
> Maybe there's something wrong with your "$list".
Nope, but maybe the behavior changed in 1.4. I'm using 1.3.1.
The list definitely exists and has elements.
-Mike
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: #set $var = (boolean exp) ==> $var = null
Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Mike,
> I suppose in retrospect since Velocity is String-oriented, this behavior is
> to be expected, but it sure seems counter-intuitive that
>
> #set ($listHasElements = ($list.size() > 0))
>
> #if ($listHasElements)
>
> for lists containing elements does not work, but
>
> #if ($list.size() > 0)
>
> does.
I wonder why it works in my environment?
#set ($listHasElements = ($list.size() > 0))
$listHasElements
should show "$listHasElements", right? But it was "true". It worked
for both 1.4 and CVS HEAD.
Maybe there's something wrong with your "$list".
Best regards,
-- Shinobu Kawai
--
Shinobu Kawai <sh...@gmail.com>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org