A Pagination Technique Using Spring

The View Layer

On the JSP layer, you need to read this object and have a way to show page links and its contents. The hidden variable p controls the page the user is viewing, and the <c:forEach loop traverses the result and displays its contents.

Note that the actual page links display logic is defined in the JSP tag "<tg:paging>"(/WEB-INF/tags/paging.tag). The pagedListHolder and current page are passed to it as parameters. The tag then correctly displays page links, including arrows and gaps in pages if the number exceeds specific display limits.

Conclusion

This article discussed a pagination mechanism based on the Spring Framework. The implementation is designed for a Java application's server layer and assumes JSP client technology. If your web or portlet project is already using Spring, adding pagination should be straightforward. The article also discussed different approaches to the pagination logic and the best layer in which to implement it.

Special thanks to Joe Zhao for providing some of the sample code for this article and guiding me in the implementation details.

Code Download

For Further Reading

About the Author

Vlad Kofman works on enterprise-scale projects for major Wall Street firms. He has also worked on defense contracts for the U.S. government. His main interests are web programming methodologies, UI patterns, and SOA.