Using apex:repeat in Visualforce Page

Using apex:repeat in Visualforce Page

Using apex:repeat in Visualforce Page

apex:repeat is 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 can’t be used as a direct child of the following components:

  • <apex:panelBar>
  • <apex:selectCheckboxes>
  • <apex:selectList>
  • <apex:selectRadio>
  • <apex:tabPanel>

 

<apex:repeat> tag has following attributes

Attribute NameAttribute TypeDescription
firstIntegerThe 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".
IdStringAn identifier that allows the repeat component to be referenced by other components in the page.
renderedBooleanA Boolean value that specifies whether the component is rendered on the page. If not specified, this value defaults to true.
rowsIntegerThe 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.
valueObjectThe collection of data that is iterated over.
varStringThe name of the variable that represents the current item in the iteration.

apex:repeat example

apex:repeat Visualforce page

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

apex:repeat Apex Code

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

For more details please refer below official link:

apex:repeat

Difference between apex:pageBlockTable and apex:repeat

When we use pageBlockTable then all salesforce styles are inherited. But when we use apex:repeat we have to manually add table tr td tags and all styles. Advantage of using apex:repeat is that we have more control on display of data.

Other similar post for visualforce

Permanent link to this article: https://www.sfdcpoint.com/salesforce/using-apexrepeat-in-visualforce-page/

1 comment

    • Sri on October 21, 2020 at 12:37 am
    • Reply

    Hi
    Could you give more examples using outputLink
    Thank you

Leave a Reply

Your email address will not be published.