How to do Lazy Pagination using JSF-Richfaces-SEAM?

Let me take you to, how to do dynamic pagination using  rich:dataTable, rich:datascroller, org.ajax4jsf.model.SerializableDataModel.  We will get into a step by step approach on implementing Lazy Pagination using JSF-Richfaces-SEAM.

Lazy Pagination using JSF-Richfaces-SEAM

Please Note: For Richfaces 4 usage, after downloading DynamicDataModel.java. Please do following two bullet points change to java class file. SerializableDataModel was removed in release of Richfaces 4.

  • Replace extends class from  org.ajax4jsf.model.SerializableDataModel to  org.ajax4jsf.model.ExtendedDataModel
  • Remove following method from class file


How to do Step by Step approach!

Step 1:

Create a Class DynamicDataModel extending org.ajax4jsf.model.SerializableDataModel; with all overridden methods.

Step 2:

Declare below given local variables to manipulate the pagination in the class.

Step 3:

And now we have to implement following methods to achieve dynamic loading of limited data required to display on the page.

Step 4:

Ignore following methods since they are never invoked by framework. However you can make use of it on need basis.

Step 5: 

Now I’m gonna explain the method walk(), vital part of implementation.

Step 6: 

We have completed Java part; let’s move on to JSF code snippet to invoke the Java class

That’s all we have to do above steps to achieve dynamic data model pagination through Lazy Pagination using JSF-Richfaces-SEAM. This approach could minimize the weight on presentation layer loading the required data for the page rather loading all the data; that are yet to be displayed in forthcoming pages assuming the data extraction calls are not so expensive.


Downloads

Code files used in the article.  Now all the Code Snippets and related files will be shared from GitHub Repo.

If you have any queries please leave a comment.