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
aamDevaamDev 

StandardSetController and Pagination

I can't seem to get the pagination to work. I've looked over various examples and my code looks good to me. I'm sure I'm missing something very obvious (at least to someone else) - please help.

 

Here's my controller class:

 

 

public with sharing class zipMap {

public String zips { get; set; }

public PageReference find() {

return null;

}

public ApexPages.StandardSetController accts {

get {

//List<String> zList = new List<String>();

//zList = zips.split(',');

accts = new ApexPages.StandardSetController(

Database.getQueryLocator(

[SELECT Id, Name, BillingStreet, BillingCity, BillingState, BillingPostalCode FROM Account WHERE BillingPostalCode = '10022' ORDER BY BillingPostalCode, Name]

)

);

accts.setPageSize(2);

return accts;

}

set;

}

public List<Account> getAccounts() {

return (List<Account>) accts.getRecords();

}

public Integer pages {

get {

pages = accts.getResultSize()/accts.getPageSize();

return pages;

}

set;

}

public Boolean hasNext {

get {

return accts.getHasNext();

}

set;

}

public Boolean hasPrevious {

get {

return accts.getHasPrevious();

}

set;

}

public Integer pageNumber {

get {

return accts.getPageNumber();

}

set;

}

public void first() {

accts.first();

}

public void last() {

accts.last();

}

public void previous() {

accts.previous();

}

public void next() {

accts.next();

}

public void cancel() {

accts.cancel();

}
}

 

 

VF:

 

 

<apex:page controller="zipMap" showHeader="false" sidebar="false" tabStyle="Account">
<apex:form >

<apex:pageBlock title="Search by Zip">
<apex:inputText value="{!zips}" />
<apex:commandButton value="Search" action="{!find}" />
</apex:pageBlock>

<apex:pageBlock title="Nearby Company/Branch">
<apex:pageBlockTable value="{!accounts}" var="acct" id="accountTable">
<apex:column headerValue="Company/Branch">
<apex:outputLink value="/{!acct.Id}" target="_top">{!acct.Name}</apex:outputLink>
</apex:column>
<apex:column headerValue="Address" colspan="2">
<apex:outputText >{!acct.BillingStreet}, {!acct.BillingCity}, {!acct.BillingState}, {!acct.BillingPostalCode}</apex:outputText>
</apex:column>
<apex:column >
<apex:outputLink value="http://maps.google.com/maps?f=d&source=s_d&saddr=&daddr={!acct.BillingStreet},{!acct.BillingCity},{!acct.BillingState},{!acct.BillingPostalCode}" target="_blank">Get Directions</apex:outputLink>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>

<apex:panelGrid columns="4">
<apex:commandLink action="{!first}" rendered="{!pages > 1}">First</apex:commandLink>
<apex:commandLink action="{!previous}" rendered="{!hasPrevious}">Previous</apex:commandLink>
<apex:commandLink action="{!next}" rendered="{!hasNext}">Next</apex:commandLink>
<apex:commandLink action="{!last}" rendered="{!pages > 1}">Last</apex:commandLink>
</apex:panelGrid>

</apex:form>
</apex:page>

 

 

Thanks!

 

Adriel

Pradeep_NavatarPradeep_Navatar

In my opinion, the issue is in the VF code, where you have used commandlink attribure rendered="{!pages > 1}". Try using  rendered = "{!IF(pages > 1,true,false)}".

 

Hope this helps.

 

 

aamDevaamDev

Thanks Pradeep,

 

It actually wasn't working before I put that attribute into the commandlink.  I'll remove it for the purposes of this post. Thanks.

 

Adriel

aamDevaamDev

Any idea on what I may be doing wrong? Thanks

sfrerssfrers

I am having identical issue getting pagination working using custom list controller.  I'm replying so I can track the thread.

aamDevaamDev
Vinay Chaturvedi_SFDCVinay Chaturvedi_SFDC
I didnt find out the link which you have posted in the last post of this thread.Can you please help me with the solution