Documentation for the worlds leading Java Based Open Source Web Content Management System

dotCMS

MillUtil

org.apache.velocity.tools.generic
Class IteratorTool

java.lang.Object
extended by org.apache.velocity.tools.generic.IteratorTool
All Implemented Interfaces:
java.util.Iterator

Deprecated. Use LoopTool instead

 

@DefaultKey(value="mill")
@Deprecated
public class IteratorTool
extends java.lang.Object
implements java.util.Iterator

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/>
</toolbox>
</tools>

Warning: It is not recommended to use hasNext() with this tool as it is used to control the #foreach. Use hasMore() instead.

Version:
$Id: IteratorTool.java 598471 2007-11-27 00:26:10Z nbubna $
Author:
Denis Bredelet

For complete documentation on this viewtool use the following link: MillUtils

2

Subscribe to dotcms

Visit this group
Please note that this documentation is for an older version of dotCMS. For the latest documentation, see: http://old.dotcms.com/docs/latest