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.

TABLE 8–11 variable Subelements (Continued)<br />

Element Description<br />

declare (optional) Whether or not the object is declared. True is the default. A translation<br />

error results if both declare and fragment are specified.<br />

scope (optional) <strong>The</strong> scope of the variable defined. Can be either AT_BEGIN, AT_END,or<br />

NESTED (see Table 8–12). Defaults to NESTED.<br />

Table 8–12 summarizes a variable’s availability according to its declared scope.<br />

TABLE 8–12 Variable Availability<br />

Value Availability<br />

NESTED Between the start tag and the end tag.<br />

AT_BEGIN From the start tag until the scope of any enclosing tag. If there’s no enclosing tag, then to the<br />

end of the page.<br />

AT_END After the end tag until the scope of any enclosing tag. If there’s no enclosing tag, then to the<br />

end of the page.<br />

You can define the following variable element for the tlt:iterator tag:<br />

<br />

<br />

var<br />

java.lang.String<br />

true<br />

NESTED<br />

<br />

<br />

Programming SimpleTag Handlers<br />

Programming SimpleTag Handlers<br />

<strong>The</strong> classes and interfaces used to implement simple tag handlers are contained in<br />

thejavax.servlet.jsp.tagext package. Simple tag handlers implement the SimpleTag<br />

interface. Interfaces can be used to take an existing <strong>Java</strong> object and make it a tag handler. For<br />

most newly created handlers, you would use the SimpleTagSupport classes as a base class.<br />

<strong>The</strong> heart of a simple tag handler is a single method, doTag, which is invoked when the end<br />

element of the tag is encountered. Note that the default implementation of the doTag method of<br />

SimpleTagSupport does nothing.<br />

A tag handler has access to an API that allows it to communicate with the JSP page. <strong>The</strong> entry<br />

point to the API is the JSP context object (javax.servlet.jsp.JspContext). <strong>The</strong> JspContext<br />

object provides access to implicit objects. PageContext extends JspContext with<br />

Chapter 8 • CustomTags in JSP Pages 253

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

Saved successfully!

Ooh no, something went wrong!