|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.velocity.tools.generic.IteratorTool
LoopTool
instead
@DefaultKey(value="mill") @Deprecated public class IteratorTool
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.
Field Summary | |
---|---|
protected Object |
next
Deprecated. |
Constructor Summary | |
---|---|
IteratorTool()
Deprecated. Create a IteratorTool instance to use as tool. |
|
IteratorTool(Object wrapped)
Deprecated. Create a IteratorTool instance to use in #foreach. |
Method Summary | |
---|---|
boolean |
hasMore()
Deprecated. Returns true if there are more elements in the wrapped list. |
boolean |
hasNext()
Deprecated. Returns true if there are more elements in the list and more() was called. |
Object |
more()
Deprecated. Asks for the next element in the list. |
Object |
next()
Deprecated. Gets the next object in the list. |
void |
remove()
Deprecated. Removes the current element from the list. |
void |
reset()
Deprecated. Resets the wrapper so that it starts over at the beginning of the list. |
void |
stop()
Deprecated. Puts a condition to break out of the loop. |
String |
toString()
Deprecated. Returns this object as a String. |
IteratorTool |
wrap(Object list)
Deprecated. Wraps a list with the tool. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected Object next
Constructor Detail |
---|
public IteratorTool()
public IteratorTool(Object wrapped)
wrapped
- The list to wrap.Method Detail |
---|
public IteratorTool wrap(Object list)
list
- The list to wrap.
public void reset()
Resets the wrapper so that it starts over at the beginning of the list.
Note to programmers: This method has no effect if the wrapped object is an enumeration or an iterator.
public Object next()
Gets the next object in the list. This method is called by #foreach to define $item in:
#foreach( $item in $list )
This method is not intended for template designers, but they can use them if they want to read the value of the next item without doing more().
next
in interface Iterator
NoSuchElementException
- if there are no more
elements in the list.public boolean hasNext()
tool.hasNext()? tool.hasNext(): false;
hasNext
in interface Iterator
public void remove() throws UnsupportedOperationException
remove
in interface Iterator
UnsupportedOperationException
- if the wrapped list
iterator doesn't support this operation.public Object more()
Asks for the next element in the list. This method is to be used by the template designer in #foreach loops.
If this method is called in the body of #foreach, the loop
continues as long as there are elements in the list.
If this method is not called the loop terminates after the
current iteration.
public boolean hasMore()
public void stop()
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |