Standard set controllers join the best of two worlds—the flexibility of Visualforce pages and the built-in power of views and searches on the Force Platform.
You already know almost everything you need to create a Visualforce page that displays multiple records from a standard controller. The one new aspect for your page is an attribute for the page tag itself. The attribute is recordSetVar, and it takes a string value. This string is the variable name for the set of records that the standard set controller makes available to the page, which will be used as the value of an iterative data component, such as a data table.
The set-based Visualforce page is working as you hoped, but you could make the navigation portion of the page a little more friendly. For instance, when you are on the first page of records, there is no need to have the Next link visible.
You can address this situation with another attribute of most Visualforce components—rendered. As the name implies, this attribute takes a Boolean value that will determine if the component is shown on the page. Standard set controllers includes values that you can use for exactly this purpose—the hasNext and hasPrevious values.
Add these attributes to the command links you previously defined. In addition, you give the outputPanel that contains these links an id attribute of "navigation", since you will want to rerender these links when the page changes. The code in the next section accomplishes this.
7. | For now, add the highlighted code to your Visualforce page: <apex:page standardController="Job_Application__c" recordSetVar="JobApps" tabstyle="JobApps__tab"> <apex:form > <apex:pageblock id="thePageBlock"> <apex:pageblocktable value="{!JobApps}" var="JA" id="candidateTable"> <apex:column value="{!JA.Name}"/> <apex:column value="{!JA.Candidate__c}"/> <apex:column value="{!JA.Candidate__r.First_Name__c}"/> <apex:column value="{!JA.Candidate__r.Last_Name__c}"/> <apex:column value="{!JA.Position__c}"/> <apex:column value="{!JA.Position__r.Job_Description__c}"> </column> </apex:pageblocktable> </apex:pageblock> <apex:panelGrid columns="2"> <apex:commandLink action="{!previous}" rendered="{!hasPrevious}"> Previous</apex:commandLink> <apex:commandLink action="{!next}" rendered="{!hasNext}"> Next</apex:commandLink> </apex:panelGrid> </apex:form> </apex:page> |
Your new page can display many records, nicely displayed a page at a time. But how many records are displayed on a page? Right now, your Visualforce page is using the default number of records, as defined for your org. But you can change this quite easily.
52.15.129.90