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.

Encapsulating Reusable Content UsingTag Files<br />

NESTED Scope In this example, the NESTED scope is used to make a<br />

variable named x available only to the tag’s body. <strong>The</strong><br />

tag sets the variable to 2, and this value is passed to<br />

the calling page before the body is invoked. Because<br />

the scope is NESTED and because the calling page also<br />

had a variable named x, its original value, 1,is<br />

restored when the tag completes.<br />

<br />

<br />

${x} <br />

<br />

${x} <br />

<br />

${x} <br />

<br />

<br />

${x} <br />

<br />

<br />

${x} <br />

<br />

AT_END Scope In this example, the AT_END scope is used to return a<br />

value to the page. <strong>The</strong> body of the tag is not affected.<br />

<br />

<br />

${x} <br />

<br />

${x} <br />

<br />

${x} <br />

<br />

<br />

${x} <br />

<br />

<br />

${x} <br />

<br />

AT_BEGIN and name-from-attribute In this example the AT_BEGIN scope is used to pass an<br />

EL variable to the tag’s body and make to it available<br />

to the calling page at the end of the tag invocation.<br />

<strong>The</strong> name of the variable is specified by the value of<br />

the attribute var. <strong>The</strong> variable is referenced by a local<br />

name, result, in the tag file.<br />

Chapter 8 • CustomTags in JSP Pages 239

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

Saved successfully!

Ooh no, something went wrong!