Visualforce Pagination in Winter ’09

There are some great new features coming down the line in Winter '09 for Visualforce. Here's a look at the pagination support.

I recently signed up for the Winter ’09 pre-release trial (details here, and also see Nick’s post), so I started playing around with all the new goodies that are coming down the line (while waiting for a flight to start my holiday!).

One feature that caught my eye was the new pagination support in Visualforce. It’s so darn simple to use.

Check out the following image, which shows a list of account names, with “next” and “previous” links.

pagination.jpg

Here’s the code (straight from the docs):

<apex:page standardController="Account" recordSetvar="accounts">
<apex:pageBlock title="ViewingAccounts">
<apex:form id="theForm">
<apex:pageBlockSection>
<apex:dataList var="a" value="{!accounts}" type="1">
{!a.name}
</apex:dataList>
</apex:pageBlockSection>
<apex:panelGrid columns="2">
<apex:commandLink action="{!previous}">Previous</apex:commandlink>
<apex:commandLink action="{!next}">Next</apex:commandlink>
</apex:panelGrid>
</apex:form>
</apex:pageBlock>
</apex:page>

I’ve highlighted the new bits:

  • The recordSetvar attribution on the page component. This associates the page with a new type of controller, the standard list controller. The attribute also indicates the variable name of the record collection. So for example, in this case it’s set to “accounts”, which is what the dataList component iterates over.
  • New methods, previous() and next()

You can easily control the number of records displayed in each page (it defaults to 25), by writing an extension:

public class tenPageSizeExt {
public tenPageSizeExt(ApexPages.StandardSetControllercontroller){
controller.setPageSize(10);
}
}

As you can see, this simply calls the (new) setPageSize() method on the controller.

Have fun, and sign up for the Winter ’09 webinar for an overview of all new features!

Published
September 20, 2008

Leave your comments...

Visualforce Pagination in Winter ’09