FieldLabel Component Index Form

Foreach
net.sf.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 no   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>
 <span jwcid="foreachCustomer">
  <tr>
   <td><span jwcid="insertId"/></td>
   <td>&nbsp;</td>
   <td><span jwcid="insertFullName"/></td>
   <td>&nbsp;</td>
   <td><span jwcid="insertMemberLevel"/></td>
  </tr>
 </span>
</table>


<component id="foreachCustomer" type="Foreach">
    <binding name="source" expression="customerList"/>
    <binding name="value" expression="customer"/>
</component>

<component id="insertId" type="Insert">
    <binding name="value" expression="customer.id"/>
</component>

<component id="insertFullName" type="Insert">
    <binding name="value" expression="customer.fullName"/>
</component>

<component id="insertMemberLevel" type="Insert">
    <binding name="value" expression="customer.memberLevel"/>
</component>


public class SalesPage extends BasePage {
    private List customerList;
    private Customer customer;
	 
    public List getCustomerList() { return customerList; }
	 
    public Customer getCustomer() { return customer; }

    public void setCustomer(Customer value) {
        customer = value;
    }

    public void detach() {
        customerList = null;
        customer = null;
        super.detach();
    }
}

public class Customer {
    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