文章目录
当你想要在VF页面上展示1000+的数据时,你就必须使用分页,否则就会报错“Collection size xxxx exceeds maximum size of 1000”。本文将教你如何使用VF自带标签实现最基本的分页功能。
一、需求阐述
自定义页面,展示系统中所有accounts的名称、类型和电话,点击名称可以进入某个account的详细页面;并且在该自定义页面中,可以编辑和删除account。
二、逻辑梳理
这个需求里并没有复杂的逻辑,实现起来也非常简单,下面直接上代码>-<
三、代码实现
1. Controller
public with sharing class SepPageCtl2 {
List<Account> accounts {get; set;}
public SepPageCtl2 (ApexPages.StandardController controller){
}
//instantiate the StandardSetController from a query locator
public ApexPages.StandardSetController con {
get{
if(con == null){
con = new ApexPages.StandardSetController(Database.getQueryLocator(
[SELECT Id, Name, Phone, Type, Industry, Owner.Name FROM Account ORDER BY Name LIMIT 100]));
// sets the number of records in each page set
con.setPageSize(5);
}
return con;
}
set;
}
// returns a list of account in the current page set
public List<Account> getAccounts(){
return (List<Account>) con.getRecords();
}
public PageReference process(){
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(){
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();
}
}
2. VF Page
<apex:page id="SepPageDemo2" standardController=