background image

A Template Tag Library

<< Tag Handler | The HttpServlet Class >>
<< Tag Handler | The HttpServlet Class >>

A Template Tag Library

this.group = group;
if(group.size() > 0)
iterator = group.iterator();
}
A Template Tag Library
A template provides a way to separate the common elements that are part of each screen from
the elements that change with each screen of an application. Putting all the common elements
together into one file makes it easier to maintain and enforce a consistent look and feel in all the
screens. It also makes development of individual screens easier because the designer can focus
on portions of a screen that are specific to that screen while the template takes care of the
common portions.
The template is a JSP page that has placeholders for the parts that need to change with each
screen. Each of these placeholders is referred to as a parameter of the template. For example, a
simple template might include a title parameter for the top of the generated screen and a body
parameter to refer to a JSP page for the custom content of the screen.
The template uses a set of nested tags (definition, screen, and parameter) to define a table of
screen definitions and uses an insert tag to insert parameters from a screen definition into a
specific application screen.
JSP Pages
The template for the Duke's Bookstore example,
tut-install/javaeetutorial5/examples/web/bookstore3/web/template/template.jsp, is
shown next. This page includes a JSP page that creates the screen definition and then uses the
insert
tag to insert parameters from the definition into the application screen.
<%@ taglib uri=
"/tutorial-template" prefix="tt" %>
<%@ page errorPage=
"/template/errorinclude.jsp" %>
<%@ include file=
"/template/screendefinitions.jsp" %>
<html>
<head>
<title>
<tt:insert definition=
"bookstore" parameter="title"/>
</title>
</head>
<body
bgcolor=
"#FFFFFF">
<tt:insert definition=
"bookstore" parameter="banner"/>
<tt:insert definition=
"bookstore" parameter="body"/>
<center><em>Copyright &copy; 2004 Sun Microsystems, Inc. </em></center>
</body>
</html>
Programming Simple Tag Handlers
Chapter 8 · Custom Tags in JSP Pages
267