org.apache.tapestry.components
Class Foreach

java.lang.Object
  extended by org.apache.tapestry.spec.BaseLocatable
      extended by org.apache.tapestry.AbstractComponent
          extended by org.apache.tapestry.components.Foreach
All Implemented Interfaces:
IComponent, ILocatable, ILocationHolder, IRender

public abstract class Foreach
extends AbstractComponent

Repeatedly renders its wrapped contents while iterating through a list of values. [Component Reference]

While the component is rendering, the property value (accessed as components.foreach.value is set to each successive value from the source, and the property index is set to each successive index into the source (starting with zero).

Version:
$Id: Foreach.java 243882 2004-04-06 18:51:56Z ehatcher $
Author:
Howard Lewis Ship

Constructor Summary
Foreach()
           
 
Method Summary
abstract  String getElement()
           
 int getIndex()
          The index number, within the source, of the the current value.
abstract  IBinding getIndexBinding()
           
abstract  Object getSource()
           
protected  Iterator getSourceData()
          Gets the source binding and returns an Iterator representing the values identified by the source.
 Object getValue()
          Returns the most recent value extracted from the source parameter.
abstract  IBinding getValueBinding()
           
protected  void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
          Gets the source binding and iterates through its values.
 
Methods inherited from class org.apache.tapestry.AbstractComponent
addAsset, addBody, addComponent, cleanupAfterRender, finishLoad, finishLoad, fireObservedChange, fireObservedChange, fireObservedChange, fireObservedChange, fireObservedChange, fireObservedChange, fireObservedChange, fireObservedChange, fireObservedChange, format, format, format, format, formatString, formatString, formatString, formatString, generateAttributes, getAsset, getAssets, getBeans, getBinding, getBindingNames, getBindings, getBody, getBodyCount, getChangeObserver, getComponent, getComponents, getContainer, getExtendedId, getId, getIdPath, getListeners, getMessage, getMessages, getNamespace, getPage, getProperty, getSpecification, getString, pageEndRender, prepareForRender, render, renderBody, renderInformalParameters, setBinding, setContainer, setId, setNamespace, setPage, setProperty, setSpecification, toString
 
Methods inherited from class org.apache.tapestry.spec.BaseLocatable
getLocation, setLocation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.tapestry.ILocationHolder
setLocation
 
Methods inherited from interface org.apache.tapestry.ILocatable
getLocation
 

Constructor Detail

Foreach

public Foreach()
Method Detail

getIndexBinding

public abstract IBinding getIndexBinding()

getSourceData

protected Iterator getSourceData()
Gets the source binding and returns an Iterator representing the values identified by the source. Returns an empty Iterator if the binding, or the binding value, is null.

Invokes Tapestry.coerceToIterator(Object) to perform the actual conversion.


getValueBinding

public abstract IBinding getValueBinding()

renderComponent

protected void renderComponent(IMarkupWriter writer,
                               IRequestCycle cycle)
Gets the source binding and iterates through its values. For each, it updates the value binding and render's its wrapped elements.

Specified by:
renderComponent in class AbstractComponent

getValue

public Object getValue()
Returns the most recent value extracted from the source parameter.

Throws:
ApplicationRuntimeException - if the Foreach is not currently rendering.

getElement

public abstract String getElement()

getSource

public abstract Object getSource()

getIndex

public int getIndex()
The index number, within the source, of the the current value.

Throws:
ApplicationRuntimeException - if the Foreach is not currently rendering.
Since:
2.2