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.

■ Using value elements, set the property of one managed bean to be the result of evaluating<br />

another value expression.<br />

This section shows you how to initialize beans using the managed bean creation facility. See<br />

“Writing Bean Properties” on page 377 and “Writing Backing Bean Methods” on page 402 for<br />

information on programming backing beans. “Binding Component Values and Instances to<br />

External Data Sources” on page 362 explains how to reference a managed bean from the<br />

component tags.<br />

Using the managed-bean Element<br />

You create a bean using a managed-bean element, which represents an instance of a bean class<br />

that must exist in the application. At runtime, the <strong>Java</strong>Server Faces implementation processes<br />

the managed-bean element. If a page references the bean, the <strong>Java</strong>Server Faces implementation<br />

instantiates the bean as specified by the element configuration if no instance exists.<br />

Here is an example managed bean configuration from the Duke’s Bookstore application:<br />

<br />

NA <br />

<br />

com.sun.bookstore6.model.ImageArea<br />

<br />

application <br />

<br />

shape<br />

poly<br />

<br />

...<br />

<br />

<br />

Configuring Beans<br />

Using NetBeans IDE, you can add a managed bean declaration by doing the following:<br />

1. After opening your project in NetBeans IDE, expand the project node in the Projects pane.<br />

2. Expand the Web Pages and WEB-INF nodes of the project node.<br />

3. Double-click faces-config.xml.<br />

4. After faces-config.xml opens in the editor pane, right-click in the editor pane.<br />

5. Select <strong>Java</strong>Server Faces → Add Managed Bean.<br />

6. In the Add Managed Bean dialog:<br />

a. Enter the display name of the bean in the Bean Name field.<br />

b. Click Browse to locate the bean’s class.<br />

7. In the Browse Class dialog:<br />

Chapter 14 • Configuring <strong>Java</strong>Server Faces Applications 437

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

Saved successfully!

Ooh no, something went wrong!