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.

Unified Expression Language<br />

164<br />

TABLE 5–5 Example Expressions (Continued)<br />

EL Expression Result<br />

${requestScope[’javax.servlet.forward.<br />

servlet_path’]}<br />

<strong>The</strong> value of the request-scoped attribute named<br />

javax.servlet.forward.servlet_path.<br />

#{customer.lName} Gets the value of the property lName from the customer bean<br />

during an initial request. Sets the value of lName during a<br />

postback.<br />

#{customer.calcTotal} <strong>The</strong> return value of the method calcTotal of the customer<br />

bean.<br />

Functions<br />

<strong>The</strong> JSP expression language allows you to define a function that can be invoked in an<br />

expression. Functions are defined using the same mechanisms as custom tags (see “Using<br />

Custom Tags” on page 170 and Chapter 8, “Custom Tags in JSP Pages”).<br />

At first glance, functions seem similar to method expressions, but they are different in the<br />

following ways:<br />

■ Functions refer to static methods that return a value. Method expressions refer to non-static,<br />

arbitrary public methods on objects.<br />

■ Functions are identified statically at translation time, whereas methods are identified<br />

dynamically at runtime.<br />

■ Function parameters and invocations are specified as part of an EL expression. A method<br />

expression only identifies a particular method. <strong>The</strong> invocation of that method is not<br />

specified by the EL expression; rather, it is specified in the tag attribute definition of the<br />

attribute using the method expression, as described in “Defining a Tag Attribute Type” on<br />

page 155.<br />

Using Functions<br />

Functions can appear in static text and tag attribute values.<br />

To use a function in a JSP page, you use a taglib directive to import the tag library containing<br />

the function. <strong>The</strong>n you preface the function invocation with the prefix declared in the directive.<br />

For example, the date example page index.jsp imports the /functions library and invokes the<br />

function equals in an expression:<br />

<br />

...<br />

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