org.apache.velocity.runtime.directive

Class Foreach

public class Foreach extends Directive

Foreach directive used for moving through arrays, or objects that provide an Iterator.

Version: $Id: Foreach.java,v 1.42.4.1 2004/03/03 23:22:55 geirm Exp $

Author: Jason van Zyl Geir Magnusson Jr.

Field Summary
intcounterInitialValue
What value to start the loop counter at.
StringcounterName
The name of the variable to use when placing the counter value into the context.
StringelementKey
The reference name used to access each of the elements in the list object.
protected InfouberInfo
immutable, so create in init
Method Summary
StringgetName()
Return name of this directive.
intgetType()
Return type of this directive.
voidinit(RuntimeServices rs, InternalContextAdapter context, Node node)
simple init - init the tree and get the elementKey from the AST
booleanrender(InternalContextAdapter context, Writer writer, Node node)
renders the #foreach() block

Field Detail

counterInitialValue

private int counterInitialValue
What value to start the loop counter at.

counterName

private String counterName
The name of the variable to use when placing the counter value into the context. Right now the default is $velocityCount.

elementKey

private String elementKey
The reference name used to access each of the elements in the list object. It is the $item in the following: #foreach ($item in $list) This can be used class wide because it is immutable.

uberInfo

protected Info uberInfo
immutable, so create in init

Method Detail

getName

public String getName()
Return name of this directive.

getType

public int getType()
Return type of this directive.

init

public void init(RuntimeServices rs, InternalContextAdapter context, Node node)
simple init - init the tree and get the elementKey from the AST

render

public boolean render(InternalContextAdapter context, Writer writer, Node node)
renders the #foreach() block
Copyright B) 2002 Apache Software Foundation. All Rights Reserved.