Newer Version Available
apex:repeat
An iteration component that allows you to output the contents of a collection according to a structure that you specify. The collection can include up to 1,000 items.
Use this component to get user input for a controller method that does not correspond to a field on an sObject. Only <apex:inputField> and <apex:outputField> can be used with sObject fields.
Note that if used within an <apex:pageBlockSection> or <apex:panelGrid> component, all content generated by a child <apex:repeat> component is placed in a single <apex:pageBlockSection> or <apex:panelGrid> cell.
This component can't be used as a direct child of the following components:
- <apex:panelBar>
- <apex:selectCheckboxes>
- <apex:selectList>
- <apex:selectRadio>
- <apex:tabPanel>
Example
1<!-- Page: -->
2
3<apex:page controller="repeatCon" id="thePage">
4
5 <apex:repeat value="{!strings}" var="string" id="theRepeat">
6
7 <apex:outputText value="{!string}" id="theValue"/><br/>
8
9 </apex:repeat>
10
11</apex:page>
12
13
14/*** Controller: ***/
15
16public class repeatCon {
17
18 public String[] getStrings() {
19 return new String[]{'ONE','TWO','THREE'};
20 }
21
22}The example above renders the following HTML:
1<span id="thePage:theRepeat:0:theValue">ONE</span><br/>
2
3<span id="thePage:theRepeat:1:theValue">TWO</span><br/>
4
5<span id="thePage:theRepeat:2:theValue">THREE</span><br/>Standard Component Example
1<!-- For this example to render properly, you must associate the Visualforce page
2
3with a valid account record in the URL.
4
5For example, if 001D000000IRt53 is the account ID, the resulting URL should be:
6
7https://MyDomain_login_URL/apex/myPage?id=001D000000IRt53
8
9See the Visualforce Developer's Guide Quick Start Tutorial for more information. -->
10
11
12
13
14
15<!-- Page: -->
16
17<apex:page standardController="Account">
18
19 <table border="0" >
20
21 <tr>
22
23 <th>Case Number</th><th>Origin</th>
24
25 <th>Creator Email</th><th>Status</th>
26
27 </tr>
28
29 <apex:repeat var="cases" value="{!Account.Cases}">
30
31 <tr>
32
33 <td>{!cases.CaseNumber}</td>
34
35 <td>{!cases.Origin}</td>
36
37 <td>{!cases.Contact.email}</td>
38
39 <td>{!cases.Status}</td>
40
41 </tr>
42
43 </apex:repeat>
44
45 </table>
46
47</apex:page>Attributes
| Attribute Name | Attribute Type | Description | Required? | API Version | Access |
|---|---|---|---|---|---|
| first | Integer | The first element in the collection visibly rendered, where 0 is the index of the first element in the set of data specified by the value attribute. For example, if you did not want to display the first two elements in the set of records specified by the value attribute, set first="2". | 10.0 | global | |
| id | String | An identifier that allows the repeat component to be referenced by other components in the page. | 10.0 | global | |
| rendered | Boolean | A Boolean value that specifies whether the component is rendered on the page. If not specified, this value defaults to true. | 10.0 | global | |
| rows | Integer | The maximum number of items in the collection that are rendered. If this value is less than the number of items in the collection, the items at the end of the collection are not repeated. | 10.0 | global | |
| value | Object | The collection of data that is iterated over. | 10.0 | global | |
| var | String | The name of the variable that represents the current item in the iteration. | 10.0 | global |