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
newbiewvfdevnewbiewvfdev 

Partial page refresh problem when using StandardSetController

Hi there,

 

I am trying out paging using StandardSetController.  Everything works fine, until I do partial page refresh.  When I add rerender="test" to the commandLink, the previous button doesn't show up when I go to the next page. Does anyone know a way around to fix this issue?

 

Here is the code:

Visual force page: <apex:page controller="PagingController"> <apex:form > <apex:pageBlock id="test" title="Paging through Categories of Stuff"> <apex:pageBlockSection title="Category Results - Page #{!pageNumber}" columns="1"> <apex:pageBlockTable value="{!Contacts}" var="c"> <apex:column value="{!c.Name}" headerValue="Name"/> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> <apex:panelGrid columns="4"> <apex:commandLink action="{!first}" rerender="test">First</apex:commandlink> <apex:commandLink action="{!previous}" rendered="{!hasPrevious}" rerender="test">Previous</apex:commandlink> <apex:commandLink action="{!next}" rendered="{!hasNext}" rerender="test">Next</apex:commandlink> <apex:commandLink action="{!last}" rerender="test">Last</apex:commandlink> </apex:panelGrid> </apex:form> </apex:page> Controller Code: public with sharing class PagingController { // instantiate the StandardSetController from a query locator public ApexPages.StandardSetController con { get { if(con == null) { con = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Name FROM Contact Order By Name])); // sets the number of records in each page set con.setPageSize(5); } return con; } set; } // indicates whether there are more records after the current page set. public Boolean hasNext { get { return con.getHasNext(); } set; } // indicates whether there are more records before the current page set. public Boolean hasPrevious { get { return con.getHasPrevious(); } set; } // returns the page number of the current page set public Integer pageNumber { get { return con.getPageNumber(); } set; } // returns the first page of records public void first() { con.first(); } // returns the last page of records public void last() { con.last(); } // returns the previous page of records public void previous() { con.previous(); } // returns the next page of records public void next() { con.next(); } // returns the PageReference of the original page, if known, or the home page. public void cancel() { con.cancel(); } public List<Contact> getContacts() { return (List<Contact>) con.getRecords(); } }

 

Best Answer chosen by Admin (Salesforce Developers) 
mtbclimbermtbclimber

Simple fix. Your controller is fine you just aren't rerendering the links:

 

 

<apex:page controller="PagingController"> <apex:form > <apex:pageBlock id="test" title="Paging through Categories of Stuff"> <apex:pageBlockSection title="Category Results - Page #{!pageNumber}" columns="1"> <apex:pageBlockTable value="{!Contacts}" var="c"> <apex:column value="{!c.Name}" headerValue="Name"/> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> <apex:panelGrid columns="4" id="links"> <apex:commandLink action="{!first}" rerender="test, links">First</apex:commandlink> <apex:commandLink action="{!previous}" rendered="{!hasPrevious}" rerender="test, links">Previous</apex:commandlink> <apex:commandLink action="{!next}" rendered="{!hasNext}" rerender="test, links">Next</apex:commandlink> <apex:commandLink action="{!last}" rerender="test, links">Last</apex:commandlink> </apex:panelGrid> </apex:form> </apex:page>

 

 

 

All Answers

mtbclimbermtbclimber

Simple fix. Your controller is fine you just aren't rerendering the links:

 

 

<apex:page controller="PagingController"> <apex:form > <apex:pageBlock id="test" title="Paging through Categories of Stuff"> <apex:pageBlockSection title="Category Results - Page #{!pageNumber}" columns="1"> <apex:pageBlockTable value="{!Contacts}" var="c"> <apex:column value="{!c.Name}" headerValue="Name"/> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> <apex:panelGrid columns="4" id="links"> <apex:commandLink action="{!first}" rerender="test, links">First</apex:commandlink> <apex:commandLink action="{!previous}" rendered="{!hasPrevious}" rerender="test, links">Previous</apex:commandlink> <apex:commandLink action="{!next}" rendered="{!hasNext}" rerender="test, links">Next</apex:commandlink> <apex:commandLink action="{!last}" rerender="test, links">Last</apex:commandlink> </apex:panelGrid> </apex:form> </apex:page>

 

 

 

This was selected as the best answer
newbiewvfdevnewbiewvfdev
Thank you very much Andrew.
mtbclimbermtbclimber

Sure thing. 

 

Thank you for posting a simple code example that isn't dependent on custom objects/fields :)  Makes helping out much, much easier.