background image

Using the managed-bean Element

<< Configuring Beans | Initializing Properties >>
<< Configuring Beans | Initializing Properties >>

Using the managed-bean Element

...
</managed-bean-name>
</managed-bean>
Using NetBeans IDE, you can add a managed bean declaration by doing the following:
1. After opening your project in NetBeans IDE, expand the project node in the Projects pane.
2. Expand the Web Pages and WEB-INF nodes of the project node.
3. Double-click faces-config.xml.
4. After faces-config.xml opens in the editor pane, right-click in the editor pane.
5. Select JavaServer Faces
Add Managed Bean.
6. In the Add Managed Bean dialog:
a. Enter the display name of the bean in the Bean Name field.
b. Click Browse to locate the bean's class.
7. In the Browse Class dialog:
a. Start typing the name of the class you are looking for in the Class Name field. While you
are typing, the dialog will show the matching classes.
b. Select the class from the Matching Classes box.
c. Click OK.
8. In the Add Managed Bean dialog:
a. Select the bean's scope from the Scope menu.
b. Click Add.
9. In the Projects tab, right-click the bookstore1 project, and select Deploy Project.
The preceding steps will add the managed-bean element and three elements inside of it: a
managed-bean-name
element, a managed-bean-class element and a managed-bean-scope
element. You will need to edit the XML of the configuration file directly to further configure this
managed bean.
The managed-bean-name element defines the key under which the bean will be stored in a scope.
For a component's value to map to this bean, the component tag's value attribute must match
the managed-bean-name up to the first period. For example, this value expression maps to the
shape
property of the ImageArea instance, NA:
value=
"#{NA.shape}"
The part before the period (.) matches the managed-bean-name of ImageArea.
"Adding UI
Components to a Page Using the HTML Component Tags" on page 327
has more examples of
using the value attribute to bind components to bean properties.
The managed-bean-class element defines the fully qualified name of the JavaBeans component
class used to instantiate the bean. It is the application developer's responsibility to ensure that
Configuring Beans
The Java EE 5 Tutorial · September 2007
440