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.

Types ofTags<br />

Simple tags are invoked using XML syntax. <strong>The</strong>y have a start tag and an end tag, and possibly a<br />

body:<br />

<br />

body<br />

A custom tag with no body is expressed as follows:<br />

or <br />

Tags with Attributes<br />

A simple tag can have attributes. Attributes customize the behavior of a custom tag just as<br />

parameters customize the behavior of a method. <strong>The</strong>re are three types of attributes:<br />

■ Simple attributes<br />

■ Fragment attributes<br />

■ Dynamic attributes<br />

Simple Attributes<br />

Simple attributes are evaluated by the container before being passed to the tag handler. Simple<br />

attributes are listed in the start tag and have the syntax attr="value". You can set a simple<br />

attribute value from a String constant, or an expression language (EL) expression, or by using a<br />

jsp:attribute element (see “jsp:attribute Element” on page 229). <strong>The</strong> conversion process<br />

between the constants and expressions and attribute types follows the rules described for<br />

<strong>Java</strong>Beans component properties in “Setting <strong>Java</strong>Beans Component Properties” on page 168.<br />

<strong>The</strong> Duke’s Bookstore page<br />

tut-install/javaeetutorial5/examples/web/bookstore3/web/bookcatalog.jsp calls the<br />

catalog tag, which has two attributes. <strong>The</strong> first attribute, a reference to a book database object,<br />

is set by an EL expression. <strong>The</strong> second attribute, which sets the color of the rows in a table that<br />

represents the bookstore catalog, is set with a String constant.<br />

<br />

Fragment Attributes<br />

A JSP fragment is a portion of JSP code passed to a tag handler that can be invoked as many<br />

times as needed. You can think of a fragment as a template that is used by a tag handler to<br />

produce customized content. Thus, unlike a simple attribute which is evaluated by the<br />

container, a fragment attribute is evaluated by a tag handler during tag invocation.<br />

Types ofTags<br />

Chapter 8 • CustomTags in JSP Pages 227

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

Saved successfully!

Ooh no, something went wrong!