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.

Encapsulating Reusable Content UsingTag Files<br />

238<br />

TABLE 8–5 Variable Synchronization Behavior<br />

Tag File Location AT_BEGIN NESTED AT_END<br />

Beginning Not sync. Save Not sync.<br />

Before any fragment invocation using<br />

jsp:invoke or jsp:doBody (see “Evaluating<br />

Fragments Passed to Tag Files” on page 240)<br />

Tag→page Tag→page Not sync.<br />

End Tag→page Restore Tag→page<br />

If name-given is used to specify the variable name, then the name of the variable in the calling<br />

page and the name of the variable in the tag file are the same and are equal to the value of<br />

name-given.<br />

<strong>The</strong> name-from-attribute and alias attributes of the variable directive can be used to<br />

customize the name of the variable in the calling page while another name is used in the tag file.<br />

When using these attributes, you set the name of the variable in the calling page from the value<br />

of name-from-attribute at the time the tag was called. <strong>The</strong> name of the corresponding variable<br />

in the tag file is the value of alias.<br />

Synchronization Examples<br />

<strong>The</strong> following examples illustrate how variable synchronization works between a tag file and its<br />

calling page. All the example JSP pages and tag files reference the JSTL core tag library with the<br />

prefix c. <strong>The</strong> JSP pages reference a tag file located in /WEB-INF/tags with the prefix my.<br />

AT_BEGIN Scope In this example, the AT_BEGIN scope is used to pass<br />

the value of the variable named x to the tag’s body<br />

and at the end of the tag invocation.<br />

<strong>The</strong> <strong>Java</strong> <strong>EE</strong> 5<strong>Tutorial</strong> • June 2010<br />

<br />

<br />

${x} <br />

<br />

${x} <br />

<br />

${x} <br />

<br />

<br />

${x} <br />

<br />

<br />

${x} <br />

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

Saved successfully!

Ooh no, something went wrong!