You could just use a getter in your controller to display the size of the list you're using in the repeat component. For example:
Public TestClass {
List<Opportunity> opps = new List<Opportunity>(); public TestClass() { // Code to populate opps }
public Integer getOppsSize() { return this.opps.size(); }
public List<Opportunity> getOpps() { return this.opps; } }
Then within your page, reference {!oppsSize} for the number of records in the repeat component and reference {!opps} within the repeat component. Let me know if that helps and answers your question.
The apex:variable technique should work with any component that does iteration - repeat, dataTable, dataList, etc. I thought I'd throw in the standard use of dataList in case that would be sufficient for your needs.
Here are a couple of options you might try....
<apex:page controller="repeaterCon"> <apex:variable value="{!1}" var="rowNum"/> <apex:repeat value="{!collection}" var="row"> ({!rowNum}){!row}<br/> <apex:variable var="rowNum" value="{!rowNum + 1}"/> </apex:repeat> <apex:dataList value="{!collection}" var="row" type="1"> {!row} </apex:dataList> </apex:page>
public class repeaterCon { public String[] collection { get; set; } public repeaterCon() { collection = new String[]{'ONE','TWO','THREE'}; } }
All Answers
You could just use a getter in your controller to display the size of the list you're using in the repeat component. For example:
Public TestClass {
List<Opportunity> opps = new List<Opportunity>();
public TestClass() {
// Code to populate opps
}
public Integer getOppsSize() {
return this.opps.size();
}
public List<Opportunity> getOpps() {
return this.opps;
}
}
Then within your page, reference {!oppsSize} for the number of records in the repeat component and reference {!opps} within the repeat component. Let me know if that helps and answers your question.
Here are a couple of options you might try....
<apex:page controller="repeaterCon"> <apex:variable value="{!1}" var="rowNum"/> <apex:repeat value="{!collection}" var="row"> ({!rowNum}){!row}<br/> <apex:variable var="rowNum" value="{!rowNum + 1}"/> </apex:repeat> <apex:dataList value="{!collection}" var="row" type="1"> {!row} </apex:dataList> </apex:page>
public class repeaterCon { public String[] collection { get; set; } public repeaterCon() { collection = new String[]{'ONE','TWO','THREE'}; } }
Thanks to reply
But i need counter means after each and every loop or repeater i want show counter Value as a sequanc.
<apex:repeat value="{!Opportunies}" var="opp1" first="0" id="theRepeatproduct">
<apex:outputText value="{!opp1.Name}"></apex:outputText>
<apex:repeat>
Output should be like that
1. Opp1Name
2. Opp2Name
.
.
.
.
.
till end of the repeater
You are right mtbclimber i need what u given. but its not working ,The output for your given code is
(1.0)01u80000002PBubAAG
(1.0)01u80000002PBucAAG
(1.0)01u80000002PBudAAG
(1.0)01u80000002PBueAAG
(1.0)01u80000002PBufAAG
...................
Can you post your code? I'm not seeing what you are seeing....
Hey sorry
Its working fine i was trying to use it without datalist i added datalist and its working fine with data list. can we do this only with repetar.
Thanks Hope it will solve my problem.
Thanks again..
This worked fine with the repeat and dataList components but now with a dataTable. See this post for more info and my workaround.
Visualforce Row Counter for Iteration Components
Jeff Douglas
Appirio, Inc.
http://blog.jeffdouglas.com