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.

Tag files bundled in a JAR require a tag library descriptor. Tag files that appear in a JAR but are<br />

not defined in a TLD are ignored by the web container.<br />

When used in a JAR file, the path subelement of the tag-file element specifies the full path of<br />

the tag file from the root of the JAR. <strong>The</strong>refore, it must always begin with /META-INF/tags/.<br />

Tag files can also be compiled into <strong>Java</strong> classes and bundled as a tag library. This is useful when<br />

you wish to distribute a binary version of the tag library without the original source. If you<br />

choose this form of packaging, you must use a tool that produces portable JSP code that uses<br />

only standard APIs.<br />

DeclaringTag Handlers<br />

When tags are implemented with tag handlers written in <strong>Java</strong>, each tag in the library must be<br />

declared in the TLD with a tag element. <strong>The</strong> tag element contains the tag name, the class of its<br />

tag handler, information on the tag’s attributes, and information on the variables created by the<br />

tag (see “Tags That Define Variables” on page 230).<br />

Each attribute declaration contains an indication of whether the attribute is required, whether<br />

its value can be determined by request-time expressions, the type of the attribute, and whether<br />

the attribute is a fragment. Variable information can be given directly in the TLD or through a<br />

tag extra info class. Table 8–9 lists the subelements of the tag element.<br />

TABLE 8–9 tag Subelements<br />

Element Description<br />

description (optional) A description of the tag.<br />

display-name (optional) name intended to be displayed by tools.<br />

icon (optional) Icon that can be used by tools.<br />

name <strong>The</strong> unique tag name.<br />

tag-class <strong>The</strong> fully qualified name of the tag handler class.<br />

tei-class (optional) Subclass of javax.servlet.jsp.tagext.TagExtraInfo. See “Declaring<br />

Tag Variables for Tag Handlers” on page 252.<br />

body-content <strong>The</strong> body content type. See “body-content Element” on page 250.<br />

Tag Library Descriptors<br />

variable (optional) Declares an EL variable exposed by the tag to the calling page. See<br />

“Declaring Tag Variables for Tag Handlers” on page 252.<br />

attribute Declares an attribute of the custom tag. See “Declaring Tag Attributes for Tag<br />

Handlers” on page 250.<br />

Chapter 8 • CustomTags in JSP Pages 249

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

Saved successfully!

Ooh no, something went wrong!