10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

What Is a CustomTag?<br />

What Is a CustomTag?<br />

A custom tag is a user-defined JSP language element. When a JSP page containing a custom tag<br />

is translated into a servlet, the tag is converted to operations on a tag handler. <strong>The</strong> web<br />

container then invokes those operations when the JSP page’s servlet is executed.<br />

Custom tags have a rich set of features. <strong>The</strong>y can<br />

■ Be customized by means of attributes passed from the calling page.<br />

■ Pass variables back to the calling page.<br />

■ Access all the objects available to JSP pages.<br />

■ Communicate with each other. You can create and initialize a <strong>Java</strong>Beans component, create<br />

a public EL variable that refers to that bean in one tag, and then use the bean in another tag.<br />

■ Be nested within one another and communicate by means of private variables.<br />

<strong>The</strong> Example JSP Pages<br />

224<br />

This chapter describes the tasks involved in defining simple tags. It illustrates the tasks using<br />

excerpts from the JSP version of the Duke’s Bookstore application discussed in “<strong>The</strong> Example<br />

JSP Pages” on page 136, rewritten here to take advantage of several custom tags:<br />

■ A catalog tag for rendering the book catalog<br />

■ A shipDate tag for rendering the ship date of an order<br />

■ A template library for ensuring a common look and feel among all screens and composing<br />

screens out of content chunks<br />

<strong>The</strong> tutorial-template tag library defines a set of tags for creating an application template.<br />

<strong>The</strong> template is a JSP page that has placeholders for the parts that need to change with each<br />

screen. Each of these placeholders is referred to as a parameter of the template. For example, a<br />

simple template might include a title parameter for the top of the generated screen and a body<br />

parameter to refer to a JSP page for the custom content of the screen. <strong>The</strong> template is created<br />

using a set of nested tags (definition, screen, and parameter) that are used to build a table of<br />

screen definitions for Duke’s Bookstore. An insert tag to insert parameters from the table into<br />

the screen.<br />

<strong>The</strong> <strong>Java</strong> <strong>EE</strong> 5<strong>Tutorial</strong> • June 2010

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!