Binding Faces managed beans to a JSF component

To work with dynamic data on your Web page, you need to define a data source, such as a Faces managed bean. Once you create a Faces Managed Bean, you can easily drag it from the Page Data view to reuse on other JSF pages.

About this task

All Faces Managed Beans for all JSF pages in a Web project display in the Page Data view and can be shared among the pages in the project.

To create a new Faces managed bean in a JSF page:

Procedure

  1. In the Data and Services drawer of the Palette, drag Faces Managed Bean onto the Web page. The Add JavaBean wizard opens.
    Note: An alternate way to create a Java™ bean is to right-click within the Page Data view and select New > Java bean.
  2. In the Name field, type a name for the Faces managed bean, for example myBirthDate.
  3. In the Class field, specify a class for the Faces managed bean, for example: java.util.Date. You can also click Search to search for a class.
  4. In the Description field, type a description for the Faces managed bean.
  5. Select a scope:
    • none: the life span is shorter than a request (example: an object created on the fly that is not accessible as a scope variable, like an instance variable).
    • application: the life span of the application running on the server session (example: a database connection).
    • session: the life span of the browser accessing the application (example: an end-user's shopping cart).
    • request: the life span of a Web page request from a browser (example: a set of detailed data based on a record in a list).
  6. Click Initialize Properties. The Initialize Java bean Properties dialog opens. Use this dialog to add properties that you want initialized.
    1. Click Add and then click within the Name field to display a list of available names or properties.
    2. Select a name from the list.
    3. Click within the Value field. You can enter a value directly or browse for a value by clicking the button to the right of this field. The Select Page Data Object dialog opens so that you can select a value.
    4. The Data Type field is filled in, depending on the property name you chose in the Name field. (Depending on the data type, an additional dialog might open in which you can add further values.)
    5. Click Add to add another property, Remove to delete the selected property, or Up and Down to change the order in which the properties display.
    6. Click OK when you are finished adding properties.
  7. Select Add input/output controls to display the Java bean on the Web page to create a form for displaying the data from the Java bean. . Click Next. The Configure Data Controls panel displays.
  8. Choose whether to create controls for Displaying data (read-only) or to create controls for Inputting data.
  9. In the Fields to display table, check all the fields that you want to display.

    Depending on the data type of a given field, you might be able to select a Control Type from a list. If the property is a list or array, a new button displays under the Control Type column. Click this button to display a wizard page on which you can select the control types for the elements of the list or array.

  10. Use the up and down arrows on the right to change the order of the fields.
  11. Click Options if you want to specify in more detail how the fields are displayed.
  12. Click Finish.

Results

If you selected Add input/output controls to display the Java bean on the Web page, the Java bean displays on the JSF page. The newly-created Java bean also displays in the Page Data view.

Feedback