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.

Resolving Expressions<br />

<strong>The</strong> unified EL introduces a new, pluggable API for resolving expressions. <strong>The</strong> main pieces of<br />

this API are:<br />

■ <strong>The</strong> ValueExpression class, which defines a value expression<br />

■ <strong>The</strong> MethodExpression class, which defines a method expression<br />

■ An ELResolver class that defines a mechanism for resolving expressions<br />

■ A set of ELResolver implementations, in which each implementation is responsible for<br />

resolving expressions that reference a particular type of object or property<br />

■ An ELContext object that saves state relating to EL resolution, holds references to EL<br />

resolvers, and contains context objects (such as JspContext) needed by the underlying<br />

technology to resolve expressions<br />

Most application developers will not need to use these classes directly unless they plan to write<br />

their own custom EL resolvers. Those writing <strong>Java</strong>Server Faces custom components will<br />

definitely need to use ValueExpression and MethodExpression. This section details how<br />

expressions are resolved for the benefit of these developers. It does not explain how to create a<br />

custom resolver. For more information on creating custom resolvers, see the article <strong>The</strong> Unified<br />

Expression Language, Ryan Lubke et al., located at http://java.sun.com/products/jsp/<br />

reference/techart/unifiedEL.html. You can also refer to “Request Processing” on page 1063,<br />

which explains how the Duke’s Bank application uses a custom resolver.<br />

Process of Expression Evaluation<br />

When a value expression that is included in a page is parsed during an initial request for the<br />

page, a ValueExpression object is created to represent the expression. <strong>The</strong>n, the<br />

ValueExpression object’s getValue method is invoked. This method will in turn invoke the<br />

getValue method of the appropriate resolver. A similar process occurs during a postback when<br />

setValue is called if the expression is an lvalue expression.<br />

In the case of a method expression, a BeanELResolver is used to find the object that implements<br />

the method to be invoked or queried. Similarly to the process for evaluating value expressions,<br />

when a method expression is encountered, a MethodExpression object is created.<br />

Subsequently, either the invoke or getMethodInfo method of the MethodExpression object is<br />

called. This method in turn invokes the BeanELResolver object’s getValue method. <strong>The</strong><br />

getMethodInfo is mostly for use by tools.<br />

After a resolver completes resolution of an expression, it sets the propertyResolved flag of the<br />

ELContext to true so that no more resolvers are consulted.<br />

EL Resolvers<br />

Unified Expression Language<br />

At the center of the EL machinery is the extensible ELResolver class. A class that implements<br />

ELResolver defines how to resolve expressions referring to a particular type of object or<br />

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

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

Saved successfully!

Ooh no, something went wrong!