A convenience tool to use with #foreach loops. It wraps a list to let the designer specify a condition to terminate the loop, and reuse the same list in different loops.
Example of use:
Java ---- context.put("mill", new IteratorTool()); VTL --- #set ($list = [1, 2, 3, 5, 8, 13]) #set ($numbers = $mill.wrap($list)) #foreach ($item in $numbers) #if ($item < 8) $numbers.more()#end #end $numbers.more() Output ------ 1 2 3 5 8 Example tools.xml config (if you want to use this with VelocityView): <tools> <toolbox scope="request"> <tool class="org.apache.velocity.tools.generic.IteratorTool"/> </toolbox> </tools>
Warning: It is not recommended to use hasNext() with this tool as it is used to control the #foreach. Use hasMore() instead.
@author Denis Bredelet @version $Id: IteratorTool.java 544680 2007-06-05 23:39:13Z nbubna $
|
|