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 />

<br />

<br />

${x} <br />

<br />

${x} <br />

${result} <br />

<br />

<br />

${x} <br />

${result} <br />

<br />

<br />

<br />

${x} <br />

${result} <br />

<br />

<br />

<br />

${x} <br />

${result} <br />

<br />

240<br />

Evaluating Fragments Passed toTag Files<br />

When a tag file is executed, the web container passes it two types of fragments: fragment<br />

attributes and the tag body. Recall from the discussion of fragment attributes that fragments are<br />

evaluated by the tag handler as opposed to the web container. Within a tag file, you use the<br />

jsp:invoke element to evaluate a fragment attribute and use the jsp:doBody element to<br />

evaluate a tag file body.<br />

<strong>The</strong> result of evaluating either type of fragment is sent to the response or is stored in an EL<br />

variable for later manipulation. To store the result of evaluating a fragment to an EL variable,<br />

you specify the var or varReader attribute. If var is specified, the container stores the result in<br />

an EL variable of type String with the name specified by var.IfvarReader is specified, the<br />

container stores the result in an EL variable of type java.io.Reader, with the name specified by<br />

varReader. <strong>The</strong> Reader object can then be passed to a custom tag for further processing. A<br />

translation error occurs if both var and varReader are specified.<br />

An optional scope attribute indicates the scope of the resulting variable. <strong>The</strong> possible values are<br />

page (default), request, session,orapplication. A translation error occurs if you use this<br />

attribute without specifying the var or varReader attribute.<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!