Effective pagination example in jsf 2

In this tutorial I will show how to create paginations in jsf2, hibernate and mysql. There are lots of built-in API for datatable paginations like PrimeFaces, RichFaces, Openfaces, SmartFaces, ICEFaces etc. but if someone wants to create his/her own pagination then it might be useful at least for beginners.

You can create this web application in any JEE based IDE like Netbeans, Eclipse etc. Before beginning you have to have the below set of jar files in your classpath. So please download the below jar files from the respective sites and put the jars under WEB-INF/lib directory.
I have created this project in Netbeans so I did not need to download any jars because the jars already available with the Netbeans.

1. Once you create the web application, create a hibernate configuration and hibernate reverse engineer files in the classpath. Here the default table ‘cdcol’ supplied with MySQL database has been used. You can use any table as per your requirements.





2. Now generate or create domain or model object for the cdcol table. XML file name does not need to contain the ‘hbm’ but it is a naming convention.





3. Create hibernate util class for creating single SessionFactory. This SessionFactory later will be used to produce non-thread-safe sessions.


4. Now create the helper class which is used to execute the queries for database transactions.


5. Now create the jsf managed bean class which will be used to interact with the view and display data to the view. Here I am not using faces-config.xml file so using the annotation. I have also kept the managed bean in ViewScope so that the state will be automatically maintained by the jsf API.


6. Now create the view file – index.xhtml. I am not using jsp file because xhtml has better support for jsf 2.x and it also supports facelets.


7. You can verify your deployment descriptor file as well.


That’s all. Thank you for your patience. If you have any question please do not forget to leave a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.