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.

Backing Beans<br />

310<br />

Notice that the application configuration resource file does not configure the userNumber<br />

property. Any property that does not have a corresponding managed-property element will be<br />

initialized to whatever the constructor of the bean class has the instance variable set to. <strong>The</strong> next<br />

section explains more about using the unified EL to reference backing beans.<br />

For more information on configuring beans using the managed bean creation Facility, see<br />

“Configuring Beans” on page 436.<br />

Using the Unified EL to Reference Backing Beans<br />

To bind UI component values and objects to backing bean properties or to reference backing<br />

bean methods from UI component tags, page authors use the unified expression language (EL)<br />

syntax defined by JSP 2.1. As explained in “Unified Expression Language” on page 146, some of<br />

the features this language offers are:<br />

■ Deferred evaluation of expressions<br />

■ <strong>The</strong> ability to use a value expression to both read and write data<br />

■ Method expressions<br />

<strong>The</strong>se features are all especially important for supporting the sophisticated UI component<br />

model offered by <strong>Java</strong>Server Faces technology.<br />

Deferred evaluation of expressions is important because the <strong>Java</strong>Server Faces life cycle is split<br />

into separate phases so that component event handling, data conversion and validation, and<br />

data propagation to external objects are all performed in an orderly fashion. <strong>The</strong><br />

implementation must be able to delay the evaluation of expressions until the proper phase of<br />

the life cycle has been reached. <strong>The</strong>refore, its tag attributes always use deferred evaluation<br />

syntax, which is distinguished by the #{} delimiters. “<strong>The</strong> Life Cycle of a <strong>Java</strong>Server Faces Page”<br />

on page 311 describes the life cycle in detail.<br />

In order to store data in external objects, almost all <strong>Java</strong>Server Faces tag attributes use lvalue<br />

value expressions, which are expressions that allow both getting and setting data on external<br />

objects.<br />

Finally, some component tag attributes accept method expressions that reference methods that<br />

handle component events, or validate or convert component data.<br />

To illustrate a <strong>Java</strong>Server Faces tag using the unified EL, let’s suppose that the userNo tag of the<br />

guessNumber application referenced a method rather than using LongRangeValidator to<br />

perform the validation of user input :<br />

<br />

This tag binds the userNo component’s value to the UserNumberBean.userNumber backing bean<br />

property using an lvalue expression. It uses a method expression to refer to the<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!