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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Tag Library Descriptors<br />

252<br />

DeclaringTagVariables forTag Handlers<br />

<strong>The</strong> example described in “Tags That Define Variables” on page 230 defines an EL variable<br />

departmentName:<br />

<br />

<br />

<br />

${departmentName}<br />

<br />

<br />

When the JSP page containing this tag is translated, the web container generates code to<br />

synchronize the variable with the object referenced by the variable. To generate the code, the<br />

web container requires certain information about the variable:<br />

■ Variable name<br />

■ Variable class<br />

■ Whether the variable refers to a new or an existing object<br />

■ <strong>The</strong> availability of the variable<br />

<strong>The</strong>re are two ways to provide this information: by specifying the variable TLD subelement or<br />

by defining a tag extra info class and including the tei-class element in the TLD (see<br />

“TagExtraInfo Class” on page 260). Using the variable element is simpler but less dynamic.<br />

With the variable element, the only aspect of the variable that you can specify at runtime is its<br />

name (with the name-from-attribute element). If you provide this information in a tag extra<br />

info class, you can also specify the type of the variable at runtime.<br />

Table 8–11 lists the subelements of the variable element.<br />

TABLE 8–11 variable Subelements<br />

Element Description<br />

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

name-given |<br />

name-from-attribute<br />

Defines an EL variable to be used in the page invoking this tag. Either name-given or<br />

name-from-attribute must be specified. If name-given is specified, the value is the<br />

name of the variable. If name-from-attribute is specified, the value is the name of an<br />

attribute whose (translation-time) value at the start of the tag invocation will give the<br />

name of the variable.<br />

Translation errors arise in the following circumstances:<br />

■ Specifying neither name-given nor name-from-attribute or both.<br />

■ If two variable elements have the same name-given.<br />

variable-class (optional) <strong>The</strong> fully qualified name of the class of the object. java.lang.String is the<br />

default.<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!