Adding a Java Bean to a Faces JSP file

Show Me

To work with dynamic data on your Web page, you need to define a data source. One data source you can use is a JavaBean.

To create a new JavaBean in a Faces JSP file:

  1. Open the Data drawer on the palette. (An alternate way to create a JavaBean is to right-click within the Page Data view and click New > JavaBean.)

  2. Drag a JavaBean component to the Faces JSP file. The Add Java Bean wizard opens.

  3. Select Add new JavaBean to create and add a JavaBean. (If you already have an existing, reusable JavaBean in your project and want to use that one, select Add existing reusable JavaBean.)

  4. Give the new JavaBean a name.

  5. Specify a Class for the JavaBean (for example: java.util.Date). You can also click the Search button to search for a Class.

  6. Check Make this JavaBean reusable if you want to make this JavaBean available to other pages. If you check this option, you can enter a description for the JavaBean and choose one of the following scopes:

    • 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. Select Add input/output controls to display the JavaBean on the Web page to create a form for displaying the data from the JavaBean.

  8. Click Initialize Properties to display the Initialize JavaBean Properties dialog. 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 of properties.

    6. Click OK when you are finished adding properties.

  9. Click Next. The Configure Data Controls panel displays.

  10. Choose whether to create controls for Displaying data (read-only) or to create controls for Inputting data.

  11. Check Invoking a method to choose a method from a list. Click Add to display the methods for the class you chose and then to select a method to invoke.

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

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

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

  15. Click Finish.

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

 

Related concepts

Data table components
Data access for Faces components
Faces components
Data table components

 

Related tasks

Adding a relational record to a Faces JSP file
Adding a relational record list to a Faces JSP file
Creating a Web service

Related reference
Faces components reference
Faces attributes reference