Friday, 18 September 2015

Pagination using Field Sets (i.e. with customizable columns) - Part # 4

Refer to my previous post on Using Field Sets in Visual force pages


This post explains the pagination in salesforce using field sets which allows easy customization of column display including 
a) what to display
b) what order/sequence

Below markup illustrates this:

Visualforce Page

<apex:page standardController="Product2"  recordsetvar="products" extensions="PaginationTutorial_4">
<apex:pageMessages id="pgm"/>
<apex:form >                     
<apex:pageBlock >
    <apex:outputPanel layout="block" styleClass="pSearchShowMore" id="otpNav2">
        Total Records Found: <apex:outputText rendered="{!IF(Con.resultSize==10000,true,false)}">10000 +</apex:outputText><apex:outputText rendered="{!IF(Con.resultSize < 10000,true,false)}">{!Con.resultSize}</apex:outputText>
        <apex:image url="/img/search_prevarrow_disabled.gif" styleClass="prevArrow" rendered="{!NOT(Con.HasPrevious)}"/>
        <apex:image url="/img/search_prevarrow.gif" title="Previous Page" styleClass="prevArrow" rendered="{!Con.HasPrevious}"/>
        <apex:commandLink action="{!Previous}" title="Previous Page" value="Previous Page" rendered="{!Con.HasPrevious}"/>
        <apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasPrevious)}">Previous Page</apex:outputPanel>         
        &nbsp;({!IF(Con.PageNumber == 1,1,((Con.PageNumber -1) * Con.PageSize)+1)}-{!IF(Con.resultSize < Con.PageSize,Con.resultSize,Con.PageNumber * Con.pageSize)})&nbsp;
        <apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasNext)}">Next Page</apex:outputPanel>         
        <apex:commandLink title="Next Page" value="Next Page" rendered="{!Con.HasNext}" action="{!Next}"/>&nbsp;
        <apex:image url="/img/search_nextarrow.gif" title="Next Page" styleClass="nextArrow" rendered="{!Con.HasNext}"/>
        <apex:image url="/img/search_nextarrow_disabled.gif" rendered="{!NOT(Con.HasNext)}"/>
    </apex:outputPanel>
    <apex:pageBlockTable value="{!products}" var="v">
        <apex:repeat value="{!$ObjectType.Product2.FieldSets.fieldSetForPagination}" var="f">
              <apex:column value="{!v[f.FieldPath]}"/>
        </apex:repeat>      
    </apex:pageBlockTable>
    <apex:outputPanel layout="block" styleClass="pSearchShowMore" id="otpNav">
        Total Records Found: <apex:outputText rendered="{!IF(Con.resultSize==10000,true,false)}">10000 +</apex:outputText><apex:outputText rendered="{!IF(Con.resultSize < 10000,true,false)}">{!Con.resultSize}</apex:outputText>
        <apex:image url="/img/search_prevarrow_disabled.gif" styleClass="prevArrow" rendered="{!NOT(Con.HasPrevious)}"/>
        <apex:image url="/img/search_prevarrow.gif" title="Previous Page" styleClass="prevArrow" rendered="{!Con.HasPrevious}"/>
        <apex:commandLink action="{!Previous}" title="Previous Page" value="Previous Page" rendered="{!Con.HasPrevious}"/>
        <apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasPrevious)}">Previous Page</apex:outputPanel>         
        &nbsp;({!IF(Con.PageNumber == 1,1,((Con.PageNumber -1) * Con.PageSize)+1)}-{!IF(Con.resultSize < Con.PageSize,Con.resultSize,Con.PageNumber * Con.pageSize)})&nbsp;
        <apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasNext)}">Next Page</apex:outputPanel>         
            <apex:commandLink title="Next Page" value="Next Page" rendered="{!Con.HasNext}" action="{!Next}"/>&nbsp;
            <apex:image url="/img/search_nextarrow.gif" title="Next Page" styleClass="nextArrow" rendered="{!Con.HasNext}"/>
            <apex:image url="/img/search_nextarrow_disabled.gif" rendered="{!NOT(Con.HasNext)}"/>          
    </apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>

Apex Class


public class PaginationTutorial_4
{    
    public ApexPages.StandardSetController con{get; set;}
    public PaginationTutorial_4(ApexPages.StandardSetController controller) 
    {
        con = controller;
        con.setPageSize(10);
    }
      
    //Boolean to check if there are more records after the present displaying records
    public Boolean hasNext
    {
        get
        {
            return con.getHasNext();
        }
        set;
    } 
    //Boolean to check if there are more records before the present displaying records
    public Boolean hasPrevious
    {
        get
        {
            return con.getHasPrevious();
        }
        set;
    } 
    //Page number of the current displaying records
    public Integer pageNumber
    {
        get
        {
            return con.getPageNumber();
        }
        set;
    }
    //Returns the previous page of records
    public void previous()
    {
        con.previous();
    } 
    //Returns the next page of records
    public void next()
    {
        con.next();
    }
}


Field Set


Preview



Advantages

  • Table columns can be customized anytime by adjusting the field set and ends as just a configuration level change
  • We can make any display level changes by directly editing visual force page
  • Both columns and its sequence of display can be controlled
  • Use the dbrequired flag on field set if the pagination is for inline editing

Disadvantages

  • Pagination is limited only to the direct object fields. That is, relationship fields cannot be included. For example, we cannot display Last Modified By user email in this table. We can include this field in the pagination, but this visual force page will fail with exception: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: LastModifiedBy.Email.
          Hence this pagination is limited only to direct fields for the object in context.
          Further blog posts will cover this exception. Stay tuned.


Tuesday, 15 September 2015

Pagination using Extension controller in addition to the Standard Controller - Part # 3

In this post we are handling the pagination functions via extension controller in addition to the standard controller.

What is Extension Controller?

controller extension is any Apex class containing a constructor that takes a single argument of type ApexPages.StandardController or CustomControllerName , where CustomControllerName is the name of a custom controller you want to extend.

Defining Extension Controller in Visualforce page:
public ApexPages.StandardSetController con{get; set;}
public PaginationTutorial_3(ApexPages.StandardSetController controller) 
{
        this.con = controller;

}


Using Extension Controller in Visualforce page:
<apex:page standardController="Product2"  recordsetvar="products" extensions="PaginationTutorial_3">
.
.
.
.
.
.
</apex:page>


The extension is associated with the page using the extensions attribute of the <apex:page> component.


Defining more than one Extension Controller:

Multiple controller extensions can be defined for a single page through a comma-separated list. This allows for overrides of methods with the same name. For example, if the following page exists:

<apex:page standardController="Account" 
    extensions="ExtOne,ExtTwo" showHeader="false">
    <apex:outputText value="{!foo}" />
</apex:page>
public class ExtOne {
    public ExtOne(ApexPages.StandardController con) { }

    public String getFoo() {
        return 'foo-One';
    }
}

public class ExtTwo {
    public ExtTwo(ApexPages.StandardController con) { }

    public String getFoo() {
        return 'foo-Two';
    }
}

The value of the <apex:outputText> component renders as foo-One. Overrides are defined by whichever methods are defined in the “leftmost” extension, or, the extension that is first in the comma-separated list. Thus, the getFoo method of ExtOne is overriding the method of ExtTwo.

Refer below markup for more details.

Visualforce Page:


<!--
Code Name   : PaginationTutorial_3
Code Type   : Visualforce
Dependency  : PaginationTutorial_3 (Apex Class)
Description : Pagination using Extension controller in addition to the Standard Controller
Author      : Bharathimohan Ramamurthy
-->
<apex:page standardController="Product2"  recordsetvar="products" extensions="PaginationTutorial_3">
<apex:pageMessages id="pgm"/>
<apex:form >                     
<apex:pageBlock >
    <apex:outputPanel layout="block" styleClass="pSearchShowMore" id="otpNav2">
        Total Records Found: <apex:outputText rendered="{!IF(Con.resultSize==10000,true,false)}">10000 +</apex:outputText><apex:outputText rendered="{!IF(Con.resultSize < 10000,true,false)}">{!Con.resultSize}</apex:outputText>
        <apex:image url="/img/search_prevarrow_disabled.gif" styleClass="prevArrow" rendered="{!NOT(Con.HasPrevious)}"/>
        <apex:image url="/img/search_prevarrow.gif" title="Previous Page" styleClass="prevArrow" rendered="{!Con.HasPrevious}"/>
        <apex:commandLink action="{!Previous}" title="Previous Page" value="Previous Page" rendered="{!Con.HasPrevious}"/>
        <apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasPrevious)}">Previous Page</apex:outputPanel>         
        &nbsp;({!IF(Con.PageNumber == 1,1,((Con.PageNumber -1) * Con.PageSize)+1)}-{!IF(Con.resultSize < Con.PageSize,Con.resultSize,Con.PageNumber * Con.pageSize)})&nbsp;
        <apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasNext)}">Next Page</apex:outputPanel>         
        <apex:commandLink title="Next Page" value="Next Page" rendered="{!Con.HasNext}" action="{!Next}"/>&nbsp;
        <apex:image url="/img/search_nextarrow.gif" title="Next Page" styleClass="nextArrow" rendered="{!Con.HasNext}"/>
        <apex:image url="/img/search_nextarrow_disabled.gif" rendered="{!NOT(Con.HasNext)}"/>          
    </apex:outputPanel>            
    <apex:pageBlockTable value="{!products}" var="v">
      <apex:column value="{!v.name}"/>
      <apex:column value="{!v.IsActive}"/>
      <apex:column value="{!v.ProductCode}"/>
      <apex:column value="{!v.RecordTypeId}"/>
      <apex:column value="{!v.CreatedbyId}"/>
      <apex:column value="{!v.CreatedBy.ProfileId}"/>      
      <apex:column value="{!v.CreatedDate}"/>
    </apex:pageBlockTable>
    <apex:outputPanel layout="block" styleClass="pSearchShowMore" id="otpNav">
        Total Records Found: <apex:outputText rendered="{!IF(Con.resultSize==10000,true,false)}">10000 +</apex:outputText><apex:outputText rendered="{!IF(Con.resultSize < 10000,true,false)}">{!Con.resultSize}</apex:outputText>
        <apex:image url="/img/search_prevarrow_disabled.gif" styleClass="prevArrow" rendered="{!NOT(Con.HasPrevious)}"/>
        <apex:image url="/img/search_prevarrow.gif" title="Previous Page" styleClass="prevArrow" rendered="{!Con.HasPrevious}"/>
        <apex:commandLink action="{!Previous}" title="Previous Page" value="Previous Page" rendered="{!Con.HasPrevious}"/>
        <apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasPrevious)}">Previous Page</apex:outputPanel>         
        &nbsp;({!IF(Con.PageNumber == 1,1,((Con.PageNumber -1) * Con.PageSize)+1)}-{!IF(Con.resultSize < Con.PageSize,Con.resultSize,Con.PageNumber * Con.pageSize)})&nbsp;
        <apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasNext)}">Next Page</apex:outputPanel>         
            <apex:commandLink title="Next Page" value="Next Page" rendered="{!Con.HasNext}" action="{!Next}"/>&nbsp;
            <apex:image url="/img/search_nextarrow.gif" title="Next Page" styleClass="nextArrow" rendered="{!Con.HasNext}"/>
            <apex:image url="/img/search_nextarrow_disabled.gif" rendered="{!NOT(Con.HasNext)}"/>          
    </apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>

Extension Controller:


public class PaginationTutorial_3
{    
    public ApexPages.StandardSetController con{get; set;}
    public PaginationTutorial_3(ApexPages.StandardSetController controller) 
    {
        this.con = controller;
        this.con.setPageSize(10);
    }
      
    //Boolean to check if there are more records after the present displaying records
    public Boolean hasNext
    {
        get
        {
            return con.getHasNext();
        }
        set;
    } 
    //Boolean to check if there are more records before the present displaying records
    public Boolean hasPrevious
    {
        get
        {
            return con.getHasPrevious();
        }
        set;
    } 
    //Page number of the current displaying records
    public Integer pageNumber
    {
        get
        {
            return con.getPageNumber();
        }
        set;
    }
    //Returns the previous page of records
    public void previous()
    {
        con.previous();
    } 
    //Returns the next page of records
    public void next()
    {
        con.next();
    }
    
    /*
        
    public List productList
    {
        get
        {
            if(con != null)
                return (List)con.getRecords();
            else
                return null ;
        }
        set;
    } 
    
    */
}


Preview:




Pros:

  • Flexibility in handling pagination via extension controller
  • Compatible design to use Field Sets, especially for Field Sets that include relationship fields (Account.Name on opportunity etc.,). We are discussing this later in another post
  • Ideal design to retrieve and display specific set of records when using SOQL explicitly

Points to Note:

  • Like other Apex classes, controller extensions run in system mode. Consequently, the current user's credentials are not used to execute controller logic, and the user's permissions and field-level security do not apply. However, if a controller extension extends a standard controller, the logic from the standard controller does not execute in system mode. Instead, it executes in user mode, in which the permissions, field-level security, and sharing rules of the current user apply
  • You can choose whether a controller extension respects a user's organization-wide defaults, role hierarchy, and sharing rules by using the with sharing keywords in the class definition

Pagination using List Views with Standard List Controllers - Part # 2

Many Salesforce pages include list views that allow you to filter the records displayed on the page. For example, on the opportunities home page, you can choose to view a list of only the opportunities you own by selecting "My Opportunities" from the list view drop-down.

On a page that is associated with a list controller, you can also use list views.

Standard List Controller Actions:

Action Description
first Displays the first page of records in the set
last Displays the last page of records in the set
next Displays the next page of records in the set
previous Displays the previous page of records in the set


For example, to create a simple list of products (as explained in Tutorial # 1) with a list view, create a page with the following markup:

Visualforce Page

<!--
Code Name   : PaginationTutorial_2
Code Type   : Visualforce
Description : Pagination using List Views with Standard List Controllers
Author      : Bharathimohan Ramamurthy
/-->
<apex:page standardController="Product2" recordSetvar="products">
<apex:form >
<apex:pageBlock title="Pagination using List Views with Standard List Controllers">
    <apex:pageBlockButtons location="top">
        <div style="float:left;font-weight:bold;">
            <apex:outputLabel value="Select View:"/>
            <apex:selectList value="{!filterId}" size="1">
                <apex:actionSupport event="onchange" rerender="myTable"/>
               <apex:selectOptions value="{!listviewoptions}"/>
            </apex:selectList>
        </div>
        <div style="float:center;font-weight:bold;">
            <apex:commandLink action="{!first}">First</apex:commandlink> &nbsp;&nbsp;
            <apex:commandLink action="{!previous}">Previous</apex:commandlink> &nbsp;&nbsp;
            <apex:commandLink action="{!next}">Next</apex:commandlink> &nbsp;&nbsp;
            <apex:commandLink action="{!last}">Last</apex:commandlink> &nbsp;&nbsp;
        </div>
    </apex:pageBlockButtons>
      <apex:pageBlockTable value="{!products}" var="v" id="myTable">
          <apex:column value="{!v.name}"/>
          <apex:column value="{!v.IsActive}"/>
          <apex:column value="{!v.ProductCode}"/>
          <apex:column value="{!v.RecordTypeId}"/>
          <apex:column value="{!v.CreatedbyId}"/>
          <apex:column value="{!v.CreatedBy.ProfileId}"/>      
          <apex:column value="{!v.CreatedDate}"/>
      </apex:pageBlockTable>           
</apex:pageBlock>
</apex:form>
</apex:page>


Preview Screenshot



Points to Note
  • When using a standard list controller, the returned records sort on the first column of data, as defined by the current view, even if that column is not rendered
  • When you use the standardController attribute on the <apex:page> tag, you cannot use the controller attribute at the same time
  • The recordSetVar attribute not only indicates that the page uses a list controller, it indicates the variable name of the record collection. This variable can then be used to access data from the record collection
  • This page does not specify a filter in the request, so the page is displayed is based on the last used filter. To check this behavior, reload your visual force page and go to the Products tab and you can observe that records displayed in first page on both these tables are same
  • Using visualforce expressions, we can access data from the records and embed to the page
  • We can traverse up to five levels of child-to-parent relationships and one level of parent-to-child relationships (Refer to Column "Profile" in screenshot for example)
  • By default, a list controller returns 20 records on the page


Pros
  • No Apex Class required and hence no test class
  • Minimal effort for development
  • No SOQL queries issued to sfdc server
  • Governor limits are not in scope for this page. However the view state limit still applies but will be minimal always as only lesser records are displayed in each page

Cons
  • No more than 10,000 records can be returned by a standard list controller. Custom controllers can work with larger results sets
  • No table sorting on records
  • No Search functionality
  • No customizations to column headers like changing label, css etc.,(Refer to Column "Profile" in screenshot for example, which suppose to be renamed as "Created User Profile" instead for better understanding)
  • You cannot filter records to be displayed inside the table dynamically through code as it was controlled by the list view

Standard List Controller Pagination-Part # 1

This post explains you the first level of pagination in salesforce using Standard list controller.

Standard list controller

Standard list controllers allow you to create Visualforce pages that can display set of records. List views, related lists, mass action pages are examples of existing Salesforce pages that work with a set of records.

Standard list controllers can be used with the following objects:

1. Account
2. Asset
3. Campaign
4. Case
5. Contact
6. Contract
7. Idea
8. Lead
9. Opportunity
10. Order
11. Product2
12. Solution
13. User
14. All Custom objects

Using a standard list controller is very similar to using a standard controller. First you set the standardController attribute on the <apex:page> component, then you set the recordSetVar attribute on the same component.

For example, to associate a page with the standard list controller for products, use the following markup:



<apex:page standardController="Product2" recordSetvar="products">

Accessing data with List Controllers
Once you have associated a page with a list controller, you can refer to the set of records using visualforce expressions. For example, to create a simple table of products, create a page with the following markup:

Visualforce Page : PaginationTutorial_1


<apex:page standardController="Product2" recordSetvar="products">
<apex:form >
<apex:pageBlock title="Product Pagination using Standard List Controller">
    <apex:pageBlockButtons location="bottom">
        <div style="float:center;font-weight:bold;">
            <apex:commandLink action="{!first}">First</apex:commandlink> &nbsp;&nbsp;
            <apex:commandLink action="{!previous}">Previous</apex:commandlink> &nbsp;&nbsp;
            <apex:commandLink action="{!next}">Next</apex:commandlink> &nbsp;&nbsp;
            <apex:commandLink action="{!last}">Last</apex:commandlink> &nbsp;&nbsp;
        </div>
    </apex:pageBlockButtons>
      <apex:pageBlockTable value="{!products}" var="v">
          <apex:column value="{!v.name}"/>
          <apex:column value="{!v.IsActive}"/>
          <apex:column value="{!v.ProductCode}"/>
          <apex:column value="{!v.RecordTypeId}"/>
          <apex:column value="{!v.CreatedbyId}"/>
          <apex:column value="{!v.CreatedBy.ProfileId}"/>      
          <apex:column value="{!v.CreatedDate}"/>
      </apex:pageBlockTable>           
</apex:pageBlock>
</apex:form>
</apex:page>


Preview


Standard List Controller Pagination-Part # 1

Points to Note
  • When you use the standardController attribute on the <apex:page> tag, you cannot use the controller attribute at the same time
  • The recordSetVar attribute not only indicates that the page uses a list controller, it indicates the variable name of the record collection. This variable can then be used to access data from the record collection
  • This page does not specify a filter in the request, so the page is displayed is based on the last used filter. To check this behavior, reload your visual force page and go to the Products tab and you can observe that records displayed in first page on both these tables are same
  • When using a standard list controller, the returned records sort on the first column of data, as defined by the current view, even if that column is not rendered. More details on "Using List Views with Standard List Controllers" was discussed in Pagination using List Views with Standard List Controllers - Part # 2.
  • Using visualforce expressions, we can access data from the records and embed to the page
  • We can traverse up to five levels of child-to-parent relationships and one level of parent-to-child relationships (Refer to Column "Profile" in screenshot for example)
  • By default, a list controller returns 20 records on the page


Pros
  • No Apex Class required and hence no test class
  • Minimal effort for development
  • No SOQL queries issued to sfdc server (at-least explicitly)
  • Governor limits are not in scope for this page. However the view state limit and heap size limit still applies but will be minimal always as only lesser records are displayed in each page

Cons
  • No more than 10,000 records can be returned by a standard list controller. Custom controllers can work with larger results sets
  • No table sorting on records
  • No Search functionality
  • No customizations to column headers like changing label, css etc.,(Refer to Column "Profile" in screenshot for example, which suppose to be renamed as "Created User Profile" instead for better understanding)
  • You cannot filter records to be displayed inside the table dynamically through code as it was controlled by the list view



Salesforce Pagination Methods, Procedures, Pros and Cons of each

What is Pagination in Salesforce?

Pagination in Salesforce is a process of dividing large amount of records from Salesforce database into multiple pages with each page at a predefined records size and presenting it to user in a page by page display. User will navigate through the pages using the navigation buttons.

What is Salesforce List Views?


Salesforce allows to create list views to see a specific set of records of all Standard Objects and all custom objects provided if objects are/can be exposed via custom tab.
For Example,
Standard Objects: Opportunity, Contacts, Accounts etc.,
Custom Objects: All (if you expose via custom tabs)

The list view criteria can be modified using the filter criteria and filter expressions. Access to these list views can be controlled by sharing the view to specific group of users or to all users. In addition, each user can also create and have their individual view not shared to others.


However, the standard list views cannot be used for most of our customization's in Visual force (refer next section).


What makes Pagination in Salesforce Important?


Standard salesforce list view pagination cannot be used in the following few scenarios,

    - Display all records chatter followed by myself in a table

    - Display all Opportunities that has a specific Product in its line item list
    - Display a specific set of records (based on criteria), that will allow user to select individual records and to some further processing/action
    - Display records in a table and allow user to change filter criteria dynamically

Hence visual force custom pagination becomes essential


Why Pagination in Salesforce is difficult?


Implementing custom pagination on a visual force is certainly not easy and it comes through practice. Developer has to win all the below limits when building pagination in order to make a successful pagination design.

Governor Limits:
Total number of records retrieved by SOQL queries

Total number of records retrieved by Database.getQueryLocator
Total heap size
Maximum CPU time on the Salesforce servers
Maximum execution time for each Apex transaction

Other Limits:
StandardSetController restrictions/limits
OFFSET limits

What are the various pagination methods/design available in salesforce?


Visualforce StandardSetController
The query and queryMore Force.com SOAP API Calls
OFFSET Clauses within SOQL Queries
Your custom logic for pagination

What is a ideal pagination design?


As such there is nothing called ideal pagination in salesforce. It depends on the actual requirement and to decide on which pagination to select.

What we are going to learn?


Further posts will explain you on all possible paginations along with actual code with screenshots. We will discuss both server side pagination and client side pagination in next posts.

Using Field Sets in Visual force pages

Field Sets in Visualforce?

Field Set in salesforce is a grouping of fields that can be used by developers to build custom visual force pages to display the fields and data using visualforce binding expressions. Administrators can later add or remove fields from the field set and the visualforce page will reflect to these changes.

Benefits?

1. By making visualforce page to use field set, we can avoid recurring changes/enhancements to the same component again and again when a field has to be added or removed
2. Free from migrations, test class coverage as no changes at component level is required
3. Component becomes dynamic
4. By passing the field set name dynamically through code, we can make the same visual force page to use different field set displaying different set of fields based on any criteria/logic
5. As field set allows selection of relationship fields and visualpage displays the same
6. Helps managed package users/subscribing orgs to use managed package field sets and let them to customize managed package VF pages to customize (only if their vendor built pages using field sets)

Below markup explains the use of Field Sets in visual force page:

Visualforce page


<!-- 
Code Name : VisualforceUsingFieldSet
Code Type  : Visualforce
Description : Using Field Set in Visualforce page
Author        : Bharathimohan Ramamurthy
/-->
<apex:page standardController="Product2" recordSetvar="products">
<apex:form >
<apex:pageBlock title="Using Field Sets in Visualforce Page">
    <apex:pageBlockButtons location="top">
        <div style="float:left;font-weight:bold;">
            <apex:outputLabel value="Select View:"/>
            <apex:selectList value="{!filterId}" size="1">
                <apex:actionSupport event="onchange" rerender="myTable"/>
               <apex:selectOptions value="{!listviewoptions}"/>
            </apex:selectList>
        </div>
        <div style="float:center;font-weight:bold;">
            <apex:commandLink action="{!first}">First</apex:commandlink> &nbsp;&nbsp;
            <apex:commandLink action="{!previous}">Previous</apex:commandlink> &nbsp;&nbsp;
            <apex:commandLink action="{!next}">Next</apex:commandlink> &nbsp;&nbsp;
            <apex:commandLink action="{!last}">Last</apex:commandlink> &nbsp;&nbsp;
        </div>
    </apex:pageBlockButtons>
      <apex:pageBlockTable value="{!products}" var="v" id="myTable">
          <apex:repeat value="{!$ObjectType.Product2.FieldSets.fieldSetForPagination}" var="f">
              <apex:column value="{!v[f.FieldPath]}"/>
        </apex:repeat>
      </apex:pageBlockTable>           
</apex:pageBlock>
</apex:form>
</apex:page>


Preview


Using Field Sets in Visual force pages


{!$ObjectType.Product2.FieldSets.fieldSetForPagination}

$ObjectType - Global Variable
Product2 - Object API Name
FieldSets - Keyword (use as such)
fieldSetForPagination - Your field set api name goes here. To access managed package field sets, use namespace as prefix with ( __ ) in between.

Considerations

1. Field will be required if visual force page is in edit mode and if the field set field is marked as required (DB required attribute determines this)
2. Maximum number of field sets that can be referenced in a page is 50 (..way beyond than ideal need for anyone)