Binding Java Beans to a JSF component

To work with dynamic data on your Web page, you need to define a data source, such as a Java™ bean. The Java beans you create can be used on a single JSF page, or, you can create Faces Managed Beans that you can reuse on any JSF page in your project.

About this task

Once you create a Faces Managed Bean, you can easily drag it from the Page Data view to reuse on other JSF pages. 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 Java bean in a JSF page:

Procedure

  1. In the Data and Services drawer of the Palette, drag JavaBean 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 Java bean, for example myBirthDate.
  3. In the Class field, specify a class for the Java bean, for example: java.util.Date. You can also click Search to search for a class.
  4. 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.
  5. Choose whether to create controls for Displaying data (read-only) or to create controls for Inputting data.
  6. Optional: Check Invoking a method, then choose a method from the list or click Add to display the methods for the class you chose.
  7. 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.

  8. Use the up and down arrows on the right to change the order of the fields.
  9. Click Options if you want to specify in more detail how the fields are displayed.
  10. Click Next for more data control configuration options.
  11. Select Create controls for displaying the results if you want input results to display.
  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