You need to sign in to do that
Don't have an account?
Dan Belwood
Using componentBody with repeat
Hello all,
Hopefully a quick question:
My page code:
My component code:
My controller:
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
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>
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"> {!p} </apex:repeat> <apex:repeat first="1" value="{!pages}" var="p"> ¤ {!p} </apex:repeat> </apex:component>
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); } }
Many thanks,
Dan
try "myvar" , call it a hunch.
so