Adding a relational record list to a Faces JSP file

Show Me

To work with dynamic data on your Web page, you need to define the data source. One dynamic data source you can use is a relational record list. With relational record lists, you can display multiple records from relational database tables.

When you define a relational record list on the page, you make its data available to the Web page. Here are a couple of ways to add a relational record list to a Faces JSP page:

To add a relational record list to your Web page by using the Data drawer:

  1. Open the Data drawer on the palette.

  2. Drag a relational record list component from the palette to the Faces JSP page where you want the data displayed. The Add Relational Record List wizard opens.

    Note: If a Target Server dialog opens, select either "WebSphere Application Server v5.1" or WebSphere Application Server v6.0" from the list and click OK.

  3. Give the record list a name to use within the page.

  4. If you have already defined a relational record list elsewhere in the project and want to use data from that list, check Reuse metadata definition from an existing record or record list and click Browse to select an input file.

  5. To automatically create a data table with fields for the data, check Add data controls. Otherwise, the record list will be added to the Page Data view and be available to the page, but controls for this list will not be generated. Later, you can drag the record list from the Page Data view to the page to display it using a data table.

  6. Click Next.

  7. On the "Record List Properties" panel, specify the connection name (or click New to create a new connection).

    1. If you click New, the New Connection panel opens.

    2. Click Create New DB Connection. The New Database Connection wizard opens. For information on creating a new database connection using this wizard, see the topic, "Connecting to a database using a wizard."

  8. Once the connection is established, select a table and click Next.

  9. On the "Column Selection and Other Tasks" panel:

    1. Select the fields to be included in the relational record list.

    2. To further refine the record list, you can click one of the following tasks or advanced tasks:

      • Modify primary key: The Edit primary keys dialog opens and lists the available columns and primary key columns. Use the arrows to make changes to the primary key columns. Note that this only defines the primary key for this record list definition and does not change the primary key on the actual database.

      • Order results: The Orders dialog opens and lists the available columns. Select the columns to order and choose how to organize them (ascending or descending).

      • Filter results: The Filters dialog opens. Click the Add (+) button to open the Conditions dialog. Here you can filter records so that only those that meet a specific condition are displayed.

      • Add another database table through a relationship: The Create Relationship wizard opens and you can create an existing relationship from the current database or create a new relationship.

      • Auto generate key: The Key Generation dialog opens. Check Use Auto Key Generation and then choose a table and the two columns you want to use for auto key generation.

      • Set concurrency control: The Concurrency dialog opens. Concurrency control lets you minimize the time during which a data resource is unavailable for use by other transactions. For example, you might have a long-running transaction which could tie up a data resource for a long time and you want to minimize that time. You can also provide column-level concurrency control. This lets you test whether the underlying data source has been updated by another transaction since pulling down the original data. The columns marked for update and their original values are added explicitly through a WHERE clause in the UPDATE statement so that the statement fails if the underlying column values have been changed. As a result, column-level concurrency control is provided. If the underlying columns have not been updated since retrieving the data initially, pending updates are committed and the locks are released. If locks cannot be acquired or if some other transaction has updated the columns since the beginning of the current transaction, the transaction is rolled back.

    3. Click Next.

  10. At the "Configure Data Controls" panel:

    1. If you previously checked Add data controls, select one of the following kinds of data controls to create:

      • Multi-Column Data Table (one table row per data entry)

      • Single Column Data Table (multiple table rows per entry)

      • Unformatted Controls in a Single Column Data Table

    2. Select which columns you want to display, enter a label for the column, and choose the control type for the each column. Control types can include Output Field, Output Formatted Text, Combo Box, Input Field, Input Text Area, and others. Use the up and down arrow keys to change the order of the columns.

    3. Click Options to set additional options. The Options dialog opens with the following tabs:

      • Labels - Contains options for the accessibility labels in the record or the data table. You can align the label so that each label is centered or aligned to the right or to the left. You can also choose to append a colon after each label and to capitalize the first letter of each label.

      • Advanced - Enter a depth level next to Depth. The depth level sets the number of levels of data that displays in the Page Data view. If you choose a depth of 3, then the Page Data view display a relational record list (or other data source) with three levels of data. For example, if the first level includes Europe, the second level includes Italy, and the third level includes Milan, then any additional levels (such as locations in Milan) do not display. In addition, levels under Milan do not appear in wizards and do not generate any controls. Check Use as default depth to change the default depth level for the user. Check Only create data controls to create only a data control on the page. If this option is not checked, the data control and other related controls are created. For example, if you are creating an Input Text component and check Only create data controls, only that component is created on the page. However, if you do not check this option, an Input Text component is created as well as a Display Errors component, a Label component, and perhaps a Submit button. Check Include <label> tags in the source code to create <label> tags that will increase the label accessibility.

      • Buttons - This tab displays if you are updating a record. You can choose to add Submit and Delete buttons to help the user update the record.

  11. Click Finish. The data source is defined for this page and displayed in the Page Data view. If you checked Add data controls, controls are generated. Otherwise, drag them from the Page Data view.

Once you have a data table on your page, you can set properties for the data table and any other components that the data table contains. Note that the Value information for the data table is already filled in.

In addition to adding a relational record list, you can also add a relational record to a Web page.

To learn more about data tables and relational record lists, about filtering a relational record list, and about automatic key generation, do the following tutorial:

Displaying dynamic information on Web pages with JavaServer Faces

 

Related concepts

Faces components
Data access for Faces components
Data table components

 

Related tasks

Creating Faces applications - overview
Creating a connection to a relational database
Connecting to a database using a wizard
Adding a relational record to a Faces JSP file
Adding a JavaBean to a Faces JSP file
Creating a Web service in a Faces JSP file
Adding a data table
Tutorial: Displaying dynamic information in Web pages with JavaServer Faces

Related reference
Faces components reference
Faces attributes reference