Class For
- java.lang.Object
 - 
- org.apache.velocity.runtime.directive.Directive
 - 
- org.apache.velocity.runtime.directive.Foreach
 - 
- org.apache.velocity.runtime.directive.contrib.For
 
 
 
 
- 
- All Implemented Interfaces:
 Cloneable,DirectiveConstants
public class For extends Foreach
The #for directive provides the behavior of the #foreach directive but also provides an 'index' keyword that allows the user to define an optional index variable that tracks the loop iterations. e.g.; #for($user in $users index $i). As $user iterates through $users the index reference $i will be equal to 0, 1, 2, etc..- See Also:
 Foreach
 
- 
- 
Field Summary
Fields Modifier and Type Field Description protected intcounterInitialValueprotected StringcounterName- 
Fields inherited from interface org.apache.velocity.runtime.directive.DirectiveConstants
BLOCK, LINE 
 - 
 
- 
Constructor Summary
Constructors Constructor Description For() 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckArgs(ArrayList<Integer> argtypes, Token t, String templateName)We do not allow a word token in any other arg position except for the 2nd since we are looking for the pattern #foreach($foo in $bar).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 ASTbooleanrender(InternalContextAdapter context, Writer writer, Node node)renders the #foreach() blockprotected voidrenderBlock(InternalContextAdapter context, Writer writer, Node node)- 
Methods inherited from class org.apache.velocity.runtime.directive.Foreach
clean, getIterator, put 
- 
Methods inherited from class org.apache.velocity.runtime.directive.Directive
getColumn, getLine, getScopeName, getTemplate, getTemplateName, isScopeProvided, makeScope, postRender, preRender, setLocation, setLocation 
 - 
 
 - 
 
- 
- 
Field Detail
- 
counterName
protected String counterName
 
- 
counterInitialValue
protected int counterInitialValue
 
 - 
 
- 
Method Detail
- 
getName
public String getName()
Description copied from class:ForeachReturn name of this directive. 
- 
getType
public int getType()
Description copied from class:ForeachReturn type of this directive. 
- 
init
public void init(RuntimeServices rs, InternalContextAdapter context, Node node) throws TemplateInitException
Description copied from class:Foreachsimple init - init the tree and get the elementKey from the AST- Overrides:
 initin classForeach- Throws:
 TemplateInitException
 
- 
render
public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException
Description copied from class:Foreachrenders the #foreach() block- Overrides:
 renderin classForeach- Returns:
 - True if the directive rendered successfully.
 - Throws:
 IOException
 
- 
renderBlock
protected void renderBlock(InternalContextAdapter context, Writer writer, Node node) throws IOException
- Overrides:
 renderBlockin classForeach- Throws:
 IOException
 
- 
checkArgs
public void checkArgs(ArrayList<Integer> argtypes, Token t, String templateName) throws ParseException
We do not allow a word token in any other arg position except for the 2nd since we are looking for the pattern #foreach($foo in $bar).- Overrides:
 checkArgsin classForeach- Parameters:
 argtypes- type, Array of argument types of each argument to the directive for example StandardParserTreeConstants.JJTWORDt- token of directivetemplateName- the name of the template this directive is referenced in.- Throws:
 ParseException
 
 - 
 
 -