Sunday, June 22, 2014

How to use apex:repeat in Visualforce Page?

How to use <apex:repeat>  in Visualforce Page?


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.

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 cannot be used as a direct child of the following components: 

< apex:dataTable >
< apex:pageBlockTable >
< apex:panelBar >
< apex:selectCheckboxes >
< apex:selectList >
< apex:selectRadio >
< apex:tabPanel >

This tag supports following attributes:
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".
An identifier that allows the repeat component to be referenced by other components in the page.
A Boolean value that specifies whether the component is rendered on the page. If not specified, this value defaults to true.
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.
The collection of data that is iterated over.
The name of the variable that represents the current item in the iteration.

Visualforce Example:

<apex:page controller="repeatCon" id="thePage">
     <apex:repeat value="{!strings}" var="string" id="theRepeat">
         <apex:outputText value="{!string}" id="theValue"/> 

Controller class:

public class repeatCon {
       public String[] getStrings() {
         return new String[]{'ONE','TWO','THREE'};

save image


Post a Comment

| ,