blob: a641555d574dd60e83d0b0845143045db2f4594f [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- $Id$ -->
<html>
<head>
<title>Foreach</title>
<link rel="stylesheet" type="text/css" href="Tapestry.css" title="style">
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left"><A href="FieldLabel.html"><IMG alt=FieldLabel src="common-images/prev.png"></a></td>
<td align="middle"><A href="index.html"><IMG alt="Component Index" src="common-images/home.png" ></a></td>
<td align="right"><A href="Form.html"><IMG alt=Form src="common-images/next.png"></a></td>
<tr>
<tr>
<td colspan="3"><hr></td>
</tr>
<tr>
<td colspan="3">
<table border="0" cellpadding="4" cellspacing="4" width="100%">
<tr valign="top">
<td>
<table>
<tr>
<td><font size="+2"><b>Foreach</b></font></td>
</tr>
<tr>
<td>
<A href="../api/org/apache/tapestry/components/Foreach.html">
org.apache.tapestry.components.Foreach</a>
</td>
</tr>
</table>
</td>
<td>
<table align="right" valign="middle" bgcolor="#c0c0c0" cellpadding="8">
<tr>
<td>Non Visual Component</td>
</tr>
</table>
</td>
</tr>
<tr valign="center">
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="2">
<b>Description</b>
<br>
A component that loops through a set of values, setting a property for each
value before rendering its wrapped elements. The <A href="ListEdit.html">
ListEdit</a> component is often more useful if the items are inside a
<A href="Form.html">Form</a>
.
</td>
</tr>
<tr>
<td colspan="2">
<b>See Also</b>
<br>
<A href="Conditional.html">Conditional</a>,
<A href="Insert.html">Insert</a>,
<A href="ListEdit.html">ListEdit</a>
</td>
</tr>
<tr>
<td colspan="2">
<b>Parameters</b>
<br>
<table border="1" cellpadding="4" cellspacing="4" class="parameters">
<tr>
<th>Name</th>
<th>Type</th>
<th>Direction</th>
<th>Required</th>
<th>Default</th>
<th>Description</th>
</tr>
<tr>
<td>source</td>
<td>
<a href="http://java.sun.com/products/jdk/1.2/docs/api/java/util/Iterator.html"><tt>Iterator</tt></a>,
<a href="http://java.sun.com/products/jdk/1.2/docs/api/java/util/Collection.html"><tt>Collection</tt></a>,
<tt>Object[]</tt>, or
<tt>Object</tt>
</td>
<td>in</td>
<td>yes</td>
<td>&nbsp;</td>
<td>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).
<p>The source parameter may even be null,
in which case the Foreach's body is never renderred.</p>
</td>
</tr>
<tr>
<td>value</td>
<td>Object</td>
<td>out</td>
<td>no</td>
<td>&nbsp;</td>
<td>Used to update the current value on each iteration.
</td>
</tr>
<tr>
<td>index</td>
<td>int</td>
<td>out</td>
<td>no</td>
<td>&nbsp;</td>
<td>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 <i>before</i> the value parameter.
</td>
</tr>
<tr>
<td>element</td>
<td>String</td>
<td>in</td>
<td>no</td>
<td>&nbsp;</td>
<td>If specified, then the component acts like an <A href="Any.html">Any</a>,
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.
</td>
</tr>
</table>
<P>Body: <STRONG>rendered</STRONG><BR>
Informal parameters: <STRONG>allowed</STRONG><br>
Reserved parameters: <EM>none</EM>
</P>
</td>
</tr>
<tr>
<td colspan="2">
<b>Examples</b>
<p>
The Foreach component is used to generate a table from a Customer List.
<p>
<table class="examples" cellspacing="6">
<tr align="left">
<th>ID</th>
<th>&nbsp;</th>
<th>Name</th>
<th>&nbsp;</th>
<th>Level</th>
</tr>
<tr>
<td colspan="5"><hr></td>
</tr>
<tr>
<td>10276</td>
<td>&nbsp;</td>
<td>Ms Sophie L. Jamies</td>
<td>&nbsp;</td>
<td>Platinum</td>
</tr>
<tr>
<td>10539</td>
<td>&nbsp;</td>
<td>Mr Albert H. Davies</td>
<td>&nbsp;</td>
<td>Gold</td>
</tr>
<tr>
<td>10552</td>
<td>&nbsp;</td>
<td>Mrs Jan S. Flawson</td>
<td>&nbsp;</td>
<td>Gold</td>
</tr>
<tr>
<td>10863</td>
<td>&nbsp;</td>
<td>Mr Robert J. Hassel</td>
<td>&nbsp;</td>
<td>Silver</td>
</tr>
</table>
<pre>
&lt;table cellspacing="6"&gt;
&lt;tr&gt;
&lt;td&gt;ID&lt;/td&gt;
&lt;td&gt;&amp;nbsp;&lt;/td&gt;
&lt;td&gt;Name&lt;/td&gt;
&lt;td&gt;&amp;nbsp;&lt;/td&gt;
&lt;td&gt;Level&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan="5"&gt;&lt;hr&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr jwcid="<span class="jwcid">@<a href="Foreach.html">Foreach</a></span>" source="ognl:customerList" value="ognl:customer" element=&quot;tr&quot;&gt;
&lt;td&gt;&lt;span jwcid="@<a href="Insert.html">Insert</a>" value="ognl:customer.id"/&gt;&lt;/td&gt;
&lt;td&gt;&amp;nbsp;&lt;/td&gt;
&lt;td&gt;&lt;span jwcid="@<a href="Insert.html">Insert</a>" value="ognl:customer.fullName"/&gt;&lt;/td&gt;
&lt;td&gt;&amp;nbsp;&lt;/td&gt;
&lt;td&gt;&lt;span jwcid="@<a href="Insert.html">Insert</a>" value="ognl:customer.memberLevel"/&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;property-specification name=&quot;customerList&quot; type=&quot;java.util.List&quot; persistent=&quot;yes&quot;/&gt;<br>&lt;property-specification name=&quot;customer&quot; type=&quot;Customer&quot;/&gt;<br>
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; }
}
</pre>
</td>
</tr></table>
</td></tr>
<tr>
<td colspan="3"><hr></td>
</tr>
<tr>
<td align="left"><A href="FieldLabel.html"><IMG alt=FieldLabel src="common-images/prev.png"></a></td>
<td align="middle"><A href="index.html"><IMG alt="Component Index" src="common-images/home.png" ></a></td>
<td align="right"><A href="Form.html"><IMG alt=Form src="common-images/next.png"></a></td>
</tr>
</table>
</body>
</html>