Skip to Main Content
Jakarta Struts Cookbook
book

Jakarta Struts Cookbook

by Bill Siggelkow
February 2005
Intermediate to advanced content levelIntermediate to advanced
528 pages
12h 53m
English
O'Reilly Media, Inc.
Content preview from Jakarta Struts Cookbook

4.5. Paging Tables

Problem

Instead of creating a long page to display a large number of tabular items, you want to display a limited fraction of the data on a page, allowing the user to navigate between the pages.

Solution

The simplest way to perform paging without resorting to a third-party tag library is to leverage the arithmetic capabilities of JSTL EL and the features of JSTL's c:forEach tag. The JSP page (paged_data.jsp) of Example 4-10 presents a complete page that supports paging through a Collection.

Example 4-10. Using JSTL for data paging

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix=
  "bean" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>
<head>
  <title>Struts Cookbook - Chapter 4 : Paging</title> </head> <body> <jsp:useBean id="pagedData" class="com.oreilly.strutsckbk.ch04. PagedData"/> <bean:size id="listSize" name="pagedData" property="data"/> <c:set var="pageSize" value="10"/> <c:set var="pageBegin" value="${param.pageBegin}"/> <c:set var="pageEnd" value="${pageBegin + pageSize - 1}"/> <c:if test="${(pageBegin - pageSize) ge 0}"> <a href='<c:url value="paged_data.jsp"> <c:param name="pageBegin" value="${pageBegin - pageSize}"/> </c:url>'> Prev </a> </c:if> &nbsp; <c:if test="${(listSize gt pageSize) and (pageEnd lt listSize)}"> <a href='<c:url value="paged_data.jsp"> <c:param name="pageBegin" value="${pageBegin + pageSize}"/> </c:url>'> Next </a> </c:if> <table ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Jakarta Struts

Programming Jakarta Struts

Chuck Cavaness
Beginning Spring Framework 2

Beginning Spring Framework 2

Bruce Snyder, Sing Li, Anne Horton, Thomas Van de Velde, Naveen Balani, Christian Dupuis
Java Cookbook

Java Cookbook

Ian F. Darwin
Struts 2 in Action

Struts 2 in Action

J. Scott Stanlick, Chad Michael Davis, Donald J. Brown

Publisher Resources

ISBN: 059600771XSupplemental ContentErrata Page