You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Eelco Hillenius <ee...@topicus.nl> on 2003/07/09 15:37:38 UTC

#foreach and nulls; bug or feature?

Hi,

When iterating a list that has null values, the last value before the null
is kept. E.g:

Take list: {"one", "two", null, null, "five").
#foreach( $val in $list)
    <tr><td>$!{val}</td></tr>
#end
will show:

one
two
two
two
five

where I expected either

one
two


five

or

one
two
five

Is this a bug or a feature?

Eelco Hillenius


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


Re: #foreach and nulls; bug or feature?. It's a bug to me. recalled!

Posted by Albert Lu <al...@nmdp.org>.
I want to recall this.

Albert Lu wrote:

> If value at the first index is null, vm does not step inside the loop at all.
> I consider this is a bug.
>
> My bean has a getter
> List[] getErrorsOnPage(){
> }
>
> in the vm template I have:
> #foreach ($errorOnPage in $formBean.errorsOnPage)
>     show me this line
> #end
>
> It did not print out any line at all.
>
> Albert Lu
>
> Eelco Hillenius wrote:
>
> > Hi,
> >
> > When iterating a list that has null values, the last value before the null
> > is kept. E.g:
> >
> > Take list: {"one", "two", null, null, "five").
> > #foreach( $val in $list)
> >     <tr><td>$!{val}</td></tr>
> > #end
> > will show:
> >
> > one
> > two
> > two
> > two
> > five
> >
> > where I expected either
> >
> > one
> > two
> >
> > five
> >
> > or
> >
> > one
> > two
> > five
> >
> > Is this a bug or a feature?
> >
> > Eelco Hillenius
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org

--
Albert Lu
National Marrow Donor Program
3433 Broadway Street NE, Suite 500
Minneapolis, MN 55413
http://www.marrow.org/
Phone: 612-627-8162
Email: alu@nmdp.org



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


Re: #foreach and nulls; bug or feature?. It's a bug to me

Posted by Albert Lu <al...@nmdp.org>.
If value at the first index is null, vm does not step inside the loop at all.
I consider this is a bug.

My bean has a getter
List[] getErrorsOnPage(){
}

in the vm template I have:
#foreach ($errorOnPage in $formBean.errorsOnPage)
    show me this line
#end

It did not print out any line at all.

Albert Lu


Eelco Hillenius wrote:

> Hi,
>
> When iterating a list that has null values, the last value before the null
> is kept. E.g:
>
> Take list: {"one", "two", null, null, "five").
> #foreach( $val in $list)
>     <tr><td>$!{val}</td></tr>
> #end
> will show:
>
> one
> two
> two
> two
> five
>
> where I expected either
>
> one
> two
>
> five
>
> or
>
> one
> two
> five
>
> Is this a bug or a feature?
>
> Eelco Hillenius
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


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


Re: #foreach and nulls; bug or feature?

Posted by Nathan Bubna <na...@esha.com>.
Will Glass-Husain said:
> I agree, it seems odd not to have this capability.  I'm generally against
> property configuration of the language, we should probably just implement it
> at some point.

+1   many have been bitten by this one.  if nothing else, it's FAQ worthy.

Nathan Bubna
nathan@esha.com


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


Re: #foreach and nulls; bug or feature?

Posted by Will Glass-Husain <wg...@forio.com>.
I agree, it seems odd not to have this capability.  I'm generally against
property configuration of the language, we should probably just implement it
at some point.

I added the text of this email to bugzilla #20999, as it seemed to be
relevant.

Best, WILL


----- Original Message ----- 
From: "Claude Brisson" <cl...@savoirweb.com>
> There have been several talks about this behaviour : allow to set null
values or not.
> To my mind, it should at least be possible to control it from the
properties.


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


Re: #foreach and nulls; bug or feature?

Posted by Claude Brisson <cl...@savoirweb.com>.
Actually, it is a behaviour of the #set directive (which is implied in the #foreach) : the log should mention that since the right
element is null in the assignation, the value will not be modified.

There have been several talks about this behaviour : allow to set null values or not.
To my mind, it should at least be possible to control it from the properties.

CloD

----- Original Message -----
From: "Eelco Hillenius" <ee...@topicus.nl>
To: "Velocity Developers List" <ve...@jakarta.apache.org>
Sent: mercredi 9 juillet 2003 15:37
Subject: #foreach and nulls; bug or feature?


> Hi,
>
> When iterating a list that has null values, the last value before the null
> is kept. E.g:
>
> Take list: {"one", "two", null, null, "five").
> #foreach( $val in $list)
>     <tr><td>$!{val}</td></tr>
> #end
> will show:
>
> one
> two
> two
> two
> five
>
> where I expected either
>
> one
> two
>
>
> five
>
> or
>
> one
> two
> five
>
> Is this a bug or a feature?
>
> Eelco Hillenius
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
>


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