velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gary M. Catlin" <gcatli...@gmail.com>
Subject Re: Working with lists
Date Fri, 19 May 2006 19:07:06 GMT
Thank you, John. Something like this worked just fine. Much obliged. gmc

Withers John Z wrote:
> Something like this should work...
>
> #set ($newList = [])
> #foreach ($record in $oldList)
>   #if ($record.property == "match")
>     #set ($n = $newList.add($record)) ## NB Assignment seems to be
> necessary
>   #end
> #end 
>
> I use this in a production application to iterate through an input list
> and group the items in the list into several other lists in Velocity.
>
> John
>
> John Withers 
>
> -----Original Message-----
> From: Gary M. Catlin [mailto:gcatlin78@gmail.com] 
> Sent: Friday, May 19, 2006 12:36 PM
> To: velocity-user@jakarta.apache.org
> Subject: Working with lists
>
> I need a little guidance on working with lists. I am attempting to copy
> a subset of the content from one list into a new list, where each
> element in the list is a class. I have been told that there is no simple
> way of filtering the content of a list, short of examining each record
> using #foreach. How do I go about creating the new list a record at a
> time? My guess would be something in the line of:
>
> #foreach ($record in $oldList)
>   #if ($record.property == "match")
>     #set ($newList[n] = $record) ** pseudo-code -- what do I really do
> here?
>   #end ## end if
> #end ## end foreach
>
> Or is there a better way to accomplish my goal?
>
> TIA.
>
> ---------------------------------------------------------------------
> 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


Mime
View raw message