Sun Java Studio Creator 2 – Online Help
 

Binding a List Component to a Database

See Also | Tutorials

When you bind a list component to a database, you create a connection between the component and at least one column in a database table. List components display one or more values at a time and include the following components from the Basic category of the Palette: Listbox, Drop Down List, Checkbox Group, and Radio Button Group.

First, set up the list component and database table in the IDE. Then, decide whether to drop the database table directly on the component or to drop the database table on the page and then bind the database table to the component. If you drop the database table directly on the component, the component is bound to the values in the first non-key column of the database table. To bind the component to another column, drop the database table on the page and then bind the component to a column of the database table.

To set up the database table and component:

  1. Add the list component to the page.
     
  2. If you are not connected to the desired database, in the Servers window, connect now.
     
  3. Expand the Tables or Views node to see the tables or views in the database.
     

To drop the database table on the component:

To drop the database table on the page and then bind the database table to the component:

  1. Drag the database table or view from the Servers window and drop it onto the page.
     
  2. Select the component to which you want to bind the data and choose Bind to Data.
     
  3. In the Bind to Data dialog box, select the Bind to Data Provider tab.
     
  4. In the Bind to Data Provider tab, in the Value field box, select the column to be returned to the database. This column usually contains primary keys.
     
  5. In the Display field box, select the column to use to display in the component at runtime.
     
  6. Click OK.
     
See Also
About Binding Components to Data
Bind to Data Dialog Box: List Component
About Components and Data
Adding Components to a Page
Adding a Data Source
Adding Tables and Views to a Page
JavaServer Faces Expression Language
Tutorials
Delving Into Components Tutorial
Working With Databases Tutorial
Using Databound Components to Access Databases Tutorial
 
 
 
Legal Notices. Copyright © 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Close