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.
With a relational record as the data source, users can create, read, update,
or delete records on Web pages.
To add a relational record to your Web page by using the Data drawer:
- Open the Data drawer on the palette.
- Drag a relational record from the palette to the Faces JSP page.
The Add Relational Record wizard opens.
Note: A page code file
is required if you want to add a relational record or relational record list
to a Faces JSP. If you have page code suppression turned on when adding a
relational record or relational record list, you are prompted to allow a page
code file to be generated.
- Specify a name to refer to the record within the page.
- If you have already defined a relational record elsewhere in the
project and want to use data from that record, check Reuse metadata
definition from an existing record or record list and click Browse to
search for an input file.
- To add data controls to the page automatically, check Add
input/output controls to display the record on the Web page. If
you do not check this, the relational record is added to the page code file
and to the Page Data view, but data components are not added to the Faces
JSP file. To add controls later, simply drag a record to the page. (Note
that an alternate way to add a relational record to your page is to use the
Page Data view instead of the Data drawer. You first create the relational
record through the Page Data view and then drag the record onto the Web page.)
- In the "Create controls for" section, select one of the following
controls when you drag the record to the page:
- Displaying an existing record (read-only):
The default component is often an Output Text component but depends on the
property's run time type. The data record is initialized to contain data from
an existing record.
- Updating an existing record: The default components
are input field components. The data record is initialized to contain data
from an existing record.
- Creating a new record: The default components
are input field components. The data record is initialized as an empty record.
The record displays as a new row in the database.
- Click Next. The Record
Properties panel opens.
- Specify the connection name or click New to
create a new connection.
- If you click New, the New Connection
panel opens.
- 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."
- Select the table you want to use from the data source.
- Click Next. The "Column
Selection and Other Tasks" panel opens.
- On the "Column Selection and Other Tasks" panel:
- Select the columns (fields) to be included in the relational
record.
- To further refine the record, 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.
- 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. Choose a collision
column [more explanation needed here]
- Click Next. The Configure Data Controls
panel opens
- On the Configure Data Controls panel:
- Select the fields you want to display, change the labels displayed
next to the fields, and select the control type to use. Depending on whether
you chose to display, update, or create a record, the 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 fields.
- Click Options if you want to create additional
options. The Options dialog opens.
- On the Labels tab of the Options dialog, 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.
- On the Advanced tab, you can 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. 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.
- If you chose to update a record, a Buttons tab also displays
on the Options dialog. On the Buttons tab, you can choose to include a Submit button
(to submit any updates) and a Delete button (to delete
the record).
- If you chose to create a record, a Buttons tab displays on the
Options dialog. On the Buttons tab, you can choose to include a Submit button
(to submit the newly created record).
- Click Finish. An HTML table
opens, containing rows and other components, based on what you selected. For
example, if you chose to update an existing record, an input text component
displays and might also include Submit and Delete buttons
to perform update record and delete record actions.
Note that the
Value information for the new
UI components is already filled in on their Properties views.
When you create
a data record, a default filter is set up to determine which record to display.
The filter looks for a record where the primary key column matches the value
in a parameter (whose name matches the primary key column name). This makes
it easy to set up an update or details page. When you link to this page, you
should pass this the value of the primary key column using this parameter.
Otherwise, the Web page will display only the values of the first record it
reads. You can change the filter by configuring the data record.
In addition to adding a relational record, you can also add a relational
record list to a Web page.
To learn more about data tables and relational
record data and about automatic key generation, do the following tutorial:
Tutorial: Display dynamic information on Web pages with JavaServer Faces. This
tutorial will teach you how to design a dynamic Web site that functions as
a newspaper's classified advertising section. The Web site is a complete J2EE
Web application that uses JavaServer Faces (JSF) components and Service Data
Objects (SDO) components. The Web application uses JSF technology to create
dynamic Web pages that link to a database that stores classified advertising
data.Tutorial:
Display dynamic information on Web pages with JavaServer Faces. This tutorial
will teach you how to design a dynamic Web site that functions as a newspaper's
classified advertising section. The Web site is a complete J2EE Web application
that uses JavaServer Faces (JSF) components and Service Data Objects (SDO)
components. The Web application uses JSF technology to create dynamic Web
pages that link to a database that stores classified advertising data.