org.apache.velocity.runtime.directive.contrib
Class For

java.lang.Object
  extended by org.apache.velocity.runtime.directive.Directive
      extended by org.apache.velocity.runtime.directive.Foreach
          extended by 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
protected  int counterInitialValue
           
protected  String counterName
           
 
Fields inherited from class org.apache.velocity.runtime.directive.Foreach
uberInfo
 
Fields inherited from class org.apache.velocity.runtime.directive.Directive
rsvc
 
Fields inherited from interface org.apache.velocity.runtime.directive.DirectiveConstants
BLOCK, LINE
 
Constructor Summary
For()
           
 
Method Summary
 void checkArgs(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).
 String getName()
          Return name of this directive.
 int getType()
          Return type of this directive.
 void init(RuntimeServices rs, InternalContextAdapter context, Node node)
          simple init - init the tree and get the elementKey from the AST
 boolean render(InternalContextAdapter context, Writer writer, Node node)
          renders the #foreach() block
protected  void renderBlock(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, getTemplateName, isScopeProvided, makeScope, postRender, preRender, setLocation, setLocation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

counterName

protected String counterName

counterInitialValue

protected int counterInitialValue
Constructor Detail

For

public For()
Method Detail

getName

public String getName()
Description copied from class: Foreach
Return name of this directive.

Overrides:
getName in class Foreach
Returns:
The name of this directive.

getType

public int getType()
Description copied from class: Foreach
Return type of this directive.

Overrides:
getType in class Foreach
Returns:
The type of this directive.

init

public void init(RuntimeServices rs,
                 InternalContextAdapter context,
                 Node node)
          throws TemplateInitException
Description copied from class: Foreach
simple init - init the tree and get the elementKey from the AST

Overrides:
init in class Foreach
Throws:
TemplateInitException

render

public boolean render(InternalContextAdapter context,
                      Writer writer,
                      Node node)
               throws IOException
Description copied from class: Foreach
renders the #foreach() block

Overrides:
render in class Foreach
Returns:
True if the directive rendered successfully.
Throws:
IOException

renderBlock

protected void renderBlock(InternalContextAdapter context,
                           Writer writer,
                           Node node)
                    throws IOException
Overrides:
renderBlock in class Foreach
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:
checkArgs in class Foreach
Parameters:
argtypes - type, Array of argument types of each argument to the directive for example ParserTreeConstants.JJTWORD
t - token of directive
templateName - the name of the template this directive is referenced in.
Throws:
ParseException


Copyright © 2000-2012 The Apache Software Foundation. All Rights Reserved.