Nathan, On 11/17/2010 4:44 PM, Nathan Bubna wrote: > On Wed, Nov 17, 2010 at 1:15 PM, Christopher Schultz > <[email protected]> wrote: >> All, >> >> I'd like to mutate a collection during template evaluation -- >> essentially, I'd like to call Iterator.remove() during a loop. Is that >> possible? Does Velocity expose an Iterator or anything like that to the >> template? > > #set( $iterator = $list.iterator() ) > #foreach( $item in $iterator ) > #if ($item.isBad() )#set( $null = $iterator.remove() )#end > #end
Duh. I was under the mistaken impression that the documentation (http://velocity.apache.org/engine/releases/velocity-1.6.4/user-guide.html#Loops) was accurate when I actually know better: you can loop over an iterator directly! >> Or, am I forced to iterate over one collection and add to another one? >> >> For that matter, is there a convenient way of creating an empty >> ArrayList or something similar? > > #set( $list = [] ) Is that documented anywhere? I'm not shocked that I get some kind of collection from that, but I don't see anything in the users guide that suggests that the above will give me a mutable collection, and if so, what kind. Thanks, -chris
signature.asc
Description: OpenPGP digital signature
