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.

Types ofTags<br />

228<br />

To declare a fragment attribute, you use the fragment attribute of the attribute directive (see<br />

“Declaring Tag Attributes in Tag Files” on page 235) or use the fragment subelement of the<br />

attribute TLD element (see “Declaring Tag Attributes for Tag Handlers” on page 250). You<br />

define the value of a fragment attribute by using a jsp:attribute element. When used to<br />

specify a fragment attribute, the body of the jsp:attribute element can contain only static text<br />

and standard and custom tags; it cannot contain scripting elements (see Chapter 9, “Scripting in<br />

JSP Pages”).<br />

JSP fragments can be parameterized by means of expression language (EL) variables in the JSP<br />

code that composes the fragment. <strong>The</strong> EL variables are set by the tag handler, thus allowing the<br />

handler to customize the fragment each time it is invoked (see “Declaring Tag Variables in Tag<br />

Files” on page 236, and “Declaring Tag Variables for Tag Handlers” on page 252).<br />

<strong>The</strong> catalog tag discussed earlier accepts two fragments: normalPrice, which is displayed for a<br />

product that’s full price, and onSale, which is displayed for a product that’s on sale.<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<strong>The</strong> tag executes the normalPrice fragment, using the values for the price EL variable, if the<br />

product is full price. If the product is on sale, the tag executes the onSale fragment using the<br />

price and salePrice variables.<br />

Dynamic Attributes<br />

A dynamic attribute is an attribute that is not specified in the definition of the tag. Dynamic<br />

attributes are used primarily by tags whose attributes are treated in a uniform manner but<br />

whose names are not necessarily known at development time.<br />

For example, this tag accepts an arbitrary number of attributes whose values are colors and<br />

outputs a bulleted list of the attributes colored according to the values:<br />

<br />

You can also set the value of dynamic attributes using an EL expression or using the<br />

jsp:attribute element.<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!