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.6. Using the Display Tag Library

Problem

You want an easier way of displaying tabular data that supports paging and sorting.

Solution

Use the Display tag JSP tag library.

Example 4-13 shows a JSP page that displays the list of U.S. presidents using the model data from Recipe 4.5. This JSP page displays a table rendered using the display tag library. The displayed page has alternating table row colors, allows for paging, and offers column sorting, all without requiring any custom Java coding.

Example 4-13. Display tag example

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://displaytag.sf.net/el" prefix="display" %>
<html>
<head>
  <title>Struts Cookbook - Chapter 4 : Display Tag Example</title>
  <style>
  .even {background-color:orange;}
  .odd {background-color:yellow;}
  </style>
</head>
<body>
  <h2>Display Tag Examples</h2>
  <jsp:useBean id="pagedData" class="com.oreilly.strutsckbk.ch04.
    PagedData"/>
  <display:table id="pres" name="${pagedData.data}"
                 sort="list" pagesize="10" defaultsort="3">
    <display:caption>United States Presidents</display:caption>
    <display:setProperty name="basic.show.header" value="true"/>
    <display:column property="firstName" title="First Name"
                    sortable="true"/>
    <display:column property="lastName" title="Last Name"
                    sortable="true"/>
    <display:column property="term" title="Term of Office"
                    sortable="true"/>
  </display:table>  
</body>
</html>

Discussion

The display tag library is an open source tag library that can be used to render highly ...

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