background image

What Is a Custom Tag

<< Custom Tags in JSP Pages | The Flow of a Request >>
<< Custom Tags in JSP Pages | The Flow of a Request >>

What Is a Custom Tag

What Is a Custom Tag?
A custom tag is a user-defined JSP language element. When a JSP page containing a custom tag
is translated into a servlet, the tag is converted to operations on a tag handler. The web
container then invokes those operations when the JSP page's servlet is executed.
Custom tags have a rich set of features. They can
Be customized by means of attributes passed from the calling page.
Pass variables back to the calling page.
Access all the objects available to JSP pages.
Communicate with each other. You can create and initialize a JavaBeans component, create
a public EL variable that refers to that bean in one tag, and then use the bean in another tag.
Be nested within one another and communicate by means of private variables.
The Example JSP Pages
This chapter describes the tasks involved in defining simple tags. It illustrates the tasks using
excerpts from the JSP version of the Duke's Bookstore application discussed in
"The Example
JSP Pages" on page 136
, rewritten here to take advantage of several custom tags:
A catalog tag for rendering the book catalog
A shipDate tag for rendering the ship date of an order
A template library for ensuring a common look and feel among all screens and composing
screens out of content chunks
The tutorial-template tag library defines a set of tags for creating an application template.
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 is created
using a set of nested tags (definition, screen, and parameter) that are used to build a table of
screen definitions for Duke's Bookstore. An insert tag to insert parameters from the table into
the screen.
What Is a Custom Tag?
The Java EE 5 Tutorial · September 2007
226