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.

Configuring a Bean<br />

<strong>Java</strong>Server Faces technology supports a sophisticated managed bean creation facility, which<br />

allows application architects to do the following:<br />

■ Configure simple beans and more complex trees of beans<br />

■ Initialize bean properties with values<br />

■ Place beans in a particular scope<br />

■ Expose the beans to the unified EL so that page authors can access them<br />

An application architect configures the beans in the application configuration resource file. To<br />

learn how to configure a managed bean, see “Configuring Beans” on page 436. <strong>The</strong> managed<br />

bean configuration used by the Guess Number example is the following:<br />

<br />

UserNumberBean<br />

<br />

guessNumber.UserNumberBean<br />

<br />

session<br />

<br />

minimum<br />

long<br />

0<br />

<br />

<br />

maximum<br />

long<br />

10<br />

<br />

<br />

<strong>The</strong> <strong>Java</strong>Server Faces implementation processes this element on application startup time. When<br />

UserNumberBean is first referenced from the page, the <strong>Java</strong>Server Faces implementation<br />

initializes it and sets the values of the properties, maximum and minimum. <strong>The</strong> bean is then stored<br />

in session scope if no instance exists. As such, the bean is available for all pages in the<br />

application.<br />

A page author can then access the bean properties from the component tags on the page using<br />

the unified EL, as shown here:<br />

<br />

Backing Beans<br />

<strong>The</strong> part of the expression before the . matches the name defined by the managed-bean-name<br />

element. <strong>The</strong> part of the expression after the . matches the name defined by the property-name<br />

element corresponding to the same managed-bean declaration.<br />

Chapter 10 • <strong>Java</strong>Server FacesTechnology 309

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

Saved successfully!

Ooh no, something went wrong!