Implementing Pagination in a JSF Page
Overview
- Pagination utility class provided in the NetBeans integrated
development environment (IDE)
- PrimeFaces
DataTable
component
Purpose
This tutorial covers the steps needed to implement the
pagination feature in a table of a JavaServer Faces (JSF) page.
Time to Complete
Approximately 45 minutes
Introduction
JSF technology is a user interface (UI) framework for developing Java web applications. It is based on components, events, and Model-View-Controller (MVC) architecture. When building web applications in JSF, you first create a page structure by arranging JSF components in a tree.
The DataTable
component displays the data as an
HTML table through the <h:dataTable>
element,
and the UIColumn
component represents a column of
data in the table. You can add several features to the DataTable
component, such as pagination,
sorting, filtering, in-cell editing, and scrolling.
The following figure shows a sample DataTable
component with pagination in a
JSF page:
Scenario
In this tutorial, you look at part of a DVD library application
from the course entitled Java EE 6: Develop Web Applications
with JSF. You view the list of DVDs and their details in a
tabular format. Next, you add a pagination feature to the table
by applying the following techniques:
- Java Platform, Standard Edition 7 (Java SE 7; Java SE 7u11
recommended)
- NetBeans 7.x IDE Java Platform, Enterprise Edition (Java EE
version; NetBeans 7.2 recommended)
- GlassFish 3.1.2 or Oracle WebLogic Server 12c
- Have some experience writing and deploying JSF web applications.
- Have installed and started NetBeans 7.2 Java EE.
- Have unzipped the DVDLibraryApp.zip file.
- Have opened the
DVDLibraryApp
project in NetBeans. - Have created the
dvdlibary
database and theItem
table and added data to theItem
table according to the instructions in theREADME
file and data in the dvdlibrary.sql file. - (Optional) Have installed WebLogic Server 12c. See the resources section for more information about installing WebLogic Server and adding it to NetBeans.
Hardware and Software Requirements
The following is a list of hardware and software requirements:
Prerequisites
Before starting this tutorial, you should:
Running and Examining the DVDLibraryApp
Project
Before starting, be sure to complete all points mentioned in the Prerequisites section.
Using the PaginationHelper
Class
You use the PaginationHelper
class and DataModel
class to implement pagination in your JSF page. Complete the
steps in the two subtopics.
Using the PaginationHelper
Class in the DVDLibraryBean
Class
Note: Add the required import statements to the
DVDLibraryBean
class.
Modifying the JSF Page to Use
the DataModel
and pagination
Fields of the DVDLibraryBean
Class
Verifying the Pagination Feature in the JSF Page
Using the PrimeFaces DataTable
Component
In this topic, you use PrimeFaces, a third-party library, to
provide the pagination feature for the DataTable
component.
Verifying the DataTable
Component in the
JSF Page
Note: You modify the numbers displayed in the combo
box by modifying the value of the rowsPerPageTemplate
attribute of the <p:dataTable>
component.
Summary
- Use the
<h:dataTable>
element in a JSF page
- Use the
javax.faces.model.DataModel
class to implement pagination
- Apply pagination in the
<h:dataTable>
element in a JSF page
- Use the PrimeFaces
<p:dataTable>
component and apply its pagination attributes in a JSF page
- Installing, Configuring, and Testing WebLogic Server 12c Developer Zip Distribution in NetBeans: This OBE covers how to install the Oracle WebLogic Server 12c (12.1.1) developer instance on Windows and configure it as a Java EE application server in NetBeans.
- Developing Applications with Java EE 6 on WebLogic Server 12c: This course covers the breadth of Java EE technologies that are part of the Java 6 Web Profile.
- Developing Web Applications using JSF Technologies: This course covers JavaServer Faces, the server-side component framework designed to simplify the development of user interfaces for Java EE applications.
- Building Database Driven Applications with JPA: This course covers JPA, the standard Java object-relational-mapping technology.
- The Java EE 6 Tutorial: The tutorial is an excellent source of information about the technologies included in Java EE 6, including CDI.
- To learn more about Java EE, visit other OBE tutorials in
the
Oracle Learning Library
- Lead Curriculum Developer: Paromita Dutta
- Reviewer: Tom McGinn
- Editor: Susan Moxley
- QA: Anjulaponni Azhagulekshmi
In this tutorial, you learned how to:
Resources
The application in this tutorial uses JSF Facelets, CDI beans, and Java Persistence API (JPA). To learn more about these technologies, see the following resources:
Credits
To help navigate this Oracle by Example, note the following:
- Hiding Header Buttons:
- Click the Title to hide the buttons in the header. To show the buttons again, simply click the Title again.
- Topic List Button:
- A list of all the topics. Click one of the topics to navigate to that section.
- Expand/Collapse All Topics:
- To show/hide all the detail for all the sections. By default, all topics are collapsed
- Show/Hide All Images:
- To show/hide all the screenshots. By default, all images are displayed.
- Print:
- To print the content. The content currently displayed or hidden will be printed.
To navigate to a particular section in this tutorial, select the topic from the list.