Sun Java Studio Creator 2 – Online Help
 

Binding a Simple Component to a Database

See Also | Tutorials

When you bind a simple component to a database, you create a connection between the component and a column in a database table. Simple components display one value at a time. For easiest data binding, use components from the Basic category of the Palette, such as Text Field.

First, set up the 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 first value in the first column of the database table. To bind the component to another column, drop the component on the page and choose the column.

To set up the database table and component:

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

To drop the database table on the component:

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

  1. Drag the database table or view from the Servers window to the Visual Designer.
     
  2. Right-click the component to which you want to bind the data and choose Bind to Data.
     
  3. In the dialog box, choose the Bind to Data Provider tab.
     
  4. Select the data provider and data field to which to bind the component and click OK.
     
    For example, in the Servers window, open Data Sources > Travel > Tables and drag the TRIPTYPE table to the page. Then, select a button and choose Bind to Data. In the Bind to Data dialog box, select the triptypeDataProvider and the TRIPTYPE.NAME column and click OK. At runtime, the button displays TRNG, which is the value in the first row in the NAME column of the TRIPTYPE table.
     
See Also
About Binding Components to Data
Bind to Data Dialog Box: Simple Display 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