Binding J2C 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 J2C Java™ bean.

  1. Create a JSF enabled dynamic Web project.

  2. Create a JSF page.

To create a new J2C Java bean in a Faces JSP file:

  1. In the Data and Services drawer of the Palette, drag

    J2C JavaBean onto the Web page. The Add J2C Java Bean wizard opens.

  2. Click

    Add to create and add a J2C Java Bean Method.

    Note: If you have an existing J2C Java Bean Method, select it from the list or click Browse to select it from your file system.

  3. In the Name field, type a name for the Faces managed bean, for example myBirthDate.

  4. 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.

  5. In the Description field, type a description for the Faces managed bean.

  6. 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).

  7. 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.

  8. 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.

  9. Choose whether to create controls for

    Displaying data (read-only) or to create controls for

    Inputting data.

  10. 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.

  11. Use the up and down arrows on the right to change the order of the fields.

  12. Click

    Options if you want to specify in more detail how the fields are displayed.

  13. Click Finish.

If you selected

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