FieldLabel Component Index Form

Foreach
org.apache.tapestry.components.Foreach
Non Visual Component
 
Description
A component that loops through a set of values, setting a property for each value before rendering its wrapped elements. The ListEdit component is often more useful if the items are inside a Form .
See Also
Conditional, Insert, ListEdit
Parameters
Name Type Direction Required Default Description
source Iterator, Collection, Object[], or Object in yes   The source of objects to be iterated, which may be a Collection, an Iterator, an array of Objects, or a even a single Object (which is treated as a singleton collection).

The source parameter may even be null, in which case the Foreach's body is never renderred.

value Object out no   Used to update the current value on each iteration.
index int out no   Used to store the index of the current value within the stream of elements provided by the source parameter. The index parameter is explicitly updated before the value parameter.
element String in no   If specified, then the component acts like an Any, emitting an open and close tag before and after each iteration. Most often, the element is "tr" when the Foreach is part of an HTML table. Any informal parameters are applied to the tag. If no element is specified, informal parameters are ignored.

Body: rendered
Informal parameters: allowed
Reserved parameters: none

Examples

The Foreach component is used to generate a table from a Customer List.

ID   Name   Level

10276   Ms Sophie L. Jamies   Platinum
10539   Mr Albert H. Davies   Gold
10552   Mrs Jan S. Flawson   Gold
10863   Mr Robert J. Hassel   Silver

<table cellspacing="6">
  <tr>
   <td>ID</td>
   <td>&nbsp;</td>
   <td>Name</td>
   <td>&nbsp;</td>
   <td>Level</td>
  </tr>
  <tr>
   <td colspan="5"><hr></td>
  </tr>
  <tr jwcid="@Foreach" source="ognl:customerList" value="ognl:customer" element="tr">
   <td><span jwcid="@Insert" value="ognl:customer.id"/></td>
   <td>&nbsp;</td>
   <td><span jwcid="@Insert" value="ognl:customer.fullName"/></td>
   <td>&nbsp;</td>
   <td><span jwcid="@Insert" value="ognl:customer.memberLevel"/></td>
  </tr>
</table>


<property-specification name="customerList" type="java.util.List" persistent="yes"/>
<property-specification name="customer" type="Customer"/>
public abstract class SalesPage extends BasePage { public abstract List getCustomerList(); public abstract void setCustomerList(List value); } public class Customer implements Serializable { private Integer id; private String fullName; private String memberLevel; public Customer(Integer id, String fullName, String memberLevel) { this.id = id; this.fullName = fullName; this.memberLevel = memberLevel; } public Integer getId() { return id; } public String getFullName() { return fullName; } public String getMemberLevel() { return memberLevel; } }

FieldLabel Component Index Form