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.

After declaring an enum constant called mySuit, you can write the following expression to test if<br />

mySuit is spade:<br />

${mySuit == "spade"}<br />

When the EL resolving mechanism resolves this expression it will invoke the valueOf method<br />

of the Enum class with the Suit class and the spade type, as shown here:<br />

mySuit.valueOf(Suit.class, "spade"}<br />

See “<strong>Java</strong>Beans Components” on page 165 for more information on using expressions to<br />

reference <strong>Java</strong>Beans components and their properties.<br />

WhereValue Expressions Can Be Used<br />

Value expressions using the ${} delimiters can be used in the following places:<br />

■ In static text<br />

■ In any standard or custom tag attribute that can accept an expression<br />

<strong>The</strong> value of an expression in static text is computed and inserted into the current output. Here<br />

is an example of an expression embedded in static text:<br />

<br />

some text ${expr} some text<br />

<br />

If the static text appears in a tag body, note that an expression will not be evaluated if the body is<br />

declared to be tagdependent (see “Tags with Attributes” on page 227).<br />

Lvalue expressions can only be used in tag attributes that can accept lvalue expressions.<br />

<strong>The</strong>re are three ways to set a tag attribute value using either an rvalue or lvalue expression:<br />

■ With a single expression construct:<br />

<br />

<br />

<strong>The</strong>se expressions are evaluated and the result is coerced to the attribute’s expected type.<br />

■ With one or more expressions separated or surrounded by text:<br />

<br />

<br />

Unified Expression Language<br />

<strong>The</strong>se kinds of expression are called a composite expressions. <strong>The</strong>y are evaluated from left to<br />

right. Each expression embedded in the composite expression is coerced to a String and<br />

then concatenated with any intervening text. <strong>The</strong> resulting String is then coerced to the<br />

attribute’s expected type.<br />

Chapter 5 • <strong>Java</strong>Server PagesTechnology 153

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

Saved successfully!

Ooh no, something went wrong!