function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dan BelwoodDan Belwood 

Using componentBody with repeat

Hello all,

Hopefully a quick question:

My page code:

Code:
<div class="middle">
        <c:PaginationComponent items="{!allTags}" var="t" itemsPerPage="10">
         <apex:outputLink value="/{!t.tag.Id}">{!t.tag.Name}</apex:outputLink>
         <br/>
        </c:PaginationComponent>
</div>

 
My component code:
Code:
<apex:component controller="PaginationComponentController">
 <apex:attribute name="items" type="Pageable[]" description="Results to paginate" required="true" assignTo="{!resultsVar}"/>
 <apex:attribute name="itemsPerPage" type="Integer" description="Items to display per page" required="true" assignTo="{!itemsPerPageVar}"/>
 <apex:attribute name="var" type="String" description="internal variable" required="true"/>
 <apex:outputText value="{!start} to {!stop} of {!size}"/>
 <br/>
 <apex:repeat value="{!items}" var="result" first="{!start - 1}" rows="{!itemsPerPage}">
  <apex:variable var="{!var}" value="{!result}"/>
  <apex:componentBody >

  </apex:componentBody>
 </apex:repeat>
 <br/>
 <apex:outputText value="Pages:"/>
 <apex:repeat first="0" rows="1" value="{!pages}" var="p">
  &nbsp;{!p}
 </apex:repeat>
 <apex:repeat first="1" value="{!pages}" var="p">
  &nbsp;&#164;&nbsp;{!p}
 </apex:repeat>
</apex:component>

 
My controller:
Code:
public class PaginationComponentController {
 private Integer index;
 public Integer start {
  get {
   return this.index + 1;
  }
 }
 public Integer stop {
  get {
   if ((this.index + this.itemsPerPageVar) > this.size) {
    return this.size;
   }
   else {
    return this.index + this.itemsPerPageVar;
   }
  }
 }
 public Integer size {
  get {
   return this.resultsVar.size();
  }
 }
 public Integer page {get;set;}
 public Integer itemsPerPageVar {get;set;}
 public Pageable[] resultsVar {get;set;}
 public Integer pageCount {
  get {
   if (this.resultsVar.size() == 0 || this.resultsVar == null) {
    return 0;
   }
   else {
    Integer count = resultsVar.size() / this.itemsPerPageVar;
    if (Math.mod(resultsVar.size(), this.itemsPerPageVar) > 0) {
     count++;
    }
    return count;
   }
  }
 }
 
 public String[] pages {
  get {
   List<String> pageArr = new List<String>();
   for (Integer i=0;i<this.pageCount;i++) {
    pageArr.add(String.valueOf(i+1));
   }
   return pageArr;
  }
 }
 
 public PageReference previous() {
  if (this.index <= this.itemsPerPageVar) {
   this.index -= this.itemsPerPageVar;
  }
  else {this.index = 0;}
  return null;
 }
 public PageReference next() {
  this.index += this.itemsPerPageVar;
  return null;
 }
 public PageReference gotoPage() {
  this.index = (this.page - 1) * this.itemsPerPageVar;
  return null;
 }
 public PageReference first() {
  this.index = 0;
  return null;
 }
 
 public PageReference last() {
  this.index = (this.pageCount - 1) * this.itemsPerPageVar;
  return null;
 }
 
 public PaginationComponentController() {
  index = 0;
 }
 
 private static Pageable[] createResults() {
  Integer total = 47;
  List<Pageable> results = new List<Pageable>();
  Code_Project__c proj;
  Pageable p;
  for (Integer i=0;i<total;i++) {
   proj = new Code_Project__c(Name='Test', Description__c='Test', Download_URL__c='http://www.google.com');
   p = new Pageable();
   p.value = proj;
   results.add(p);
  }
  return results;
 }
 
 static testMethod void testPageCount() {
  PaginationComponentController con = new PaginationComponentController();
  con.itemsPerPageVar = 10;
  con.resultsVar = createResults();
  System.assertEquals(5, con.pageCount);
 }
 static testMethod void testPageCountNone() {
  PaginationComponentController con = new PaginationComponentController();
  con.itemsPerPageVar = 10;
  System.assertEquals(0, con.pageCount);
 }
 static testMethod void testNext() {
  PaginationComponentController con = new PaginationComponentController();
  con.itemsPerPageVar = 10;
  con.resultsVar = createResults();
  System.assertEquals(0, con.index);
  con.next();
  System.assertEquals(10, con.index);
 }
 static testMethod void testPrevious() {
  PaginationComponentController con = new PaginationComponentController();
  con.itemsPerPageVar = 10;
  con.resultsVar = createResults();
  System.assertEquals(0, con.index);
  con.next();
  System.assertEquals(10, con.index);
  con.previous();
  System.assertEquals(0, con.index);
 }
 static testMethod void testPreviousFirst() {
  PaginationComponentController con = new PaginationComponentController();
  con.itemsPerPageVar = 10;
  con.resultsVar = createResults();
  System.assertEquals(0, con.index);
  con.previous();
  System.assertEquals(0, con.index);
 }
 static testMethod void testNextLast() {
  PaginationComponentController con = new PaginationComponentController();
  con.itemsPerPageVar = 10;
  con.resultsVar = createResults();
  con.page = 5;
  con.gotoPage();
  con.next();
  System.assertEquals(40, con.index);
 }
 static testMethod void testGotoPage() {
  PaginationComponentController con = new PaginationComponentController();
  con.itemsPerPageVar = 10;
  con.resultsVar = createResults();
  System.assertEquals(0, con.index);
  con.page = 5;
  con.gotoPage();
  System.assertEquals(40, con.index);
  con.page = 3;
  con.gotoPage();
  System.assertEquals(20, con.index);
 }
 static testMethod void testPages() {
  PaginationComponentController con = new PaginationComponentController();
  con.itemsPerPageVar = 10;
  con.resultsVar = createResults();
  List<String> testArr = new List<String>{'1', '2', '3', '4' , '5'};
  System.assertEquals(testArr, con.pages);
 }
}

 
the {!allTags} method  returns a list of Pageable objects which are just SObjects, but I can use a List of SObjects as an attribute value.  When I run this page, the first tag's data is displayed, then 10 blank rows.  Any ideas?

Many thanks,
Dan
Ron HessRon Hess
sounds strange but try changing the name of your variable , don't use "var"

try "myvar" , call it a hunch.

so
<apex:attribute name="myvar"

and

<apex:variable var="{!myvar}"