I implemented pagination on my visual force page looking at these two resources. http://hisrinu.wordpress.com/2012/01/09/pagination-using-standardsetcontroller/ http://blog.jeffdouglas.com/2009/07/14/visualforce-page-with-pagination/
My visualforce page accepts date parameters and runs a search on custom object records and displays them in an Apex:datatable.
Here is my controller code. This works fine until I begin click the next, previous links continuously for about a minute and then it begins to slow down and freeze up.
Any idea why this is happening?
UPDATE: 7/28: This is happening only in IE. I have IE 9.
public with sharing class FundingReportController {
// the soql without the order and limit
private String soql {get;set;}
Public Integer size{get;set;}
Public Integer noOfRecords{get; set;}
//export to excel - returns a page reference to the AccountDataExcel page
public PageReference exportToExcel() {
return Page.fundingreportExcel;
}
//Instantiate the StandardSetController
public ApexPages.StandardSetController con{get; set;}
public List<Money_Transaction__c> moneyTransactions
{
get
{
if(con != null)
return (List<Money_Transaction__c>)con.getRecords();
else
return null ;
}
set;
}
// returns a list of wrapper objects for the sObjects in the current page set
public List<Money_Transaction__c> getMoneyTransactions() {
try{
//moneyTransactions = new List<MoneyTransactionWrapper>();
moneyTransactions = new List<Money_Transaction__c>();
for (Money_Transaction__c mt: (List<Money_Transaction__c>)con.getRecords())
{
moneyTransactions.add(mt);
}
}
catch (Exception e)
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Code Error '+e));
}
return moneyTransactions ;
}
// the current sort direction. defaults to asc
public String sortDir {
get { if (sortDir == null) { sortDir = 'asc'; } return sortDir; }
set;
}
// the current field to sort by. defaults to last name
public String sortField {
get { if (sortField == null) {sortField = 'Settlement_Date_First__c'; } return sortField; }
set;
}
// format the soql for display on the visualforce page
public String debugSoql {
//get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
get { return soql + ' ' + sortDir; }
set;
}
// init the controller and display some sample data when the page loads
public FundingReportController() {
moneyTransactions = new List<Money_Transaction__c>();
//Default dates: 6 months before today
Date fromDate = date.today();
fromDate = fromDate.addMonths(-6);
String fromDateStr = String.ValueOf(fromDate);
//ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,fromDateStr ));
//Default dates: Today
Date toDate = date.today();
String toDateStr = String.ValueOf(toDate);
soql = 'select ACH_Type__c, Settlement_Date_First__c, Total_ACH_Amount__c,Settlement__r.id,Settlement__r.name,Money_Movement_Type__c,Bank_Name__c,Bank_Account_Number__c,Tax_Batch__c,Payroll_Group_Detail__c from Money_Transaction__c where Settlement_Date_First__c <= '+ toDateStr + ' AND Settlement_Date_First__c >= ' + fromDateStr + ' AND ACH_Type__c != \'VHR DDP Disbursement\'';
runQuery();
}
// toggles the sorting of query from asc<-->desc
public void toggleSort() {
//ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Inside Toggle'+soql + sortField +sortDir ));
// simply toggle the direction
sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
// run the query again
runQuery();
}
// runs the actual query
public void runQuery() {
try {
size=10;
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Inside New Run query + StandardSetController '+soql + ' order by ' + sortField + ' ' + sortDir));
con = new ApexPages.StandardSetController(Database.getQueryLocator(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 100'));
// sets the number of records in each page set
con.setPageSize(size);
noOfRecords = con.getResultSize();
} catch (Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops! SOQL error '+soql ));
}
}
// runs the search with parameters passed via Javascript
public PageReference runSearch() {
String fromDate = Apexpages.currentPage().getParameters().get('fromDate');
String toDate = Apexpages.currentPage().getParameters().get('toDate');
soql = 'select ACH_Type__c, Settlement_Date_First__c, Total_ACH_Amount__c,Settlement__r.id,Settlement__r.name,Money_Movement_Type__c,Bank_Name__c,Bank_Account_Number__c,Tax_Batch__c,Payroll_Group_Detail__c from Money_Transaction__c where Settlement_Date_First__c <= '+ toDate + ' AND Settlement_Date_First__c >= ' + fromDate + ' AND ACH_Type__c != \'VHR DDP Disbursement\'';
con = new ApexPages.StandardSetController(Database.getQueryLocator(soql));
// run the query again
runQuery();
return null;
}
// 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() {
try{
con.first();
}
catch (Exception e)
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Code Error '+e));
}
}
// returns the last page of records
public void last() {
try{
con.last();
}
catch (Exception e)
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Code Error '+e));
}
}
// returns the previous page of records
public void previous() {
try{
con.previous();
}
catch (Exception e)
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Code Error '+e));
}
}
// returns the next page of records
public void next() {
try{
con.next();
}
catch (Exception e)
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Code Error '+e));
}
}
}
This project was stalled for some months. I returned to it and this time I used SOQL with the new OFFSET feature and got rid of the standardcontroller.
The actual issue was IE9 itself and I have posted the details and the solution here. I hope it helps someone with the same re-rendering issues with IE9 and Visualforce.
Thanks.