Note: We recommend that you print this tutorial for easy reference. To print, click on the right-hand frame before accessing your HTML Browser's File/Print command.
Most of the time you will probably use textual data fields (such as XiDBDataField) to allow the user to enter data into your application, but sometimes you may want to present the user with a set of choices.
In this tutorial you will create an application that allows the user to choose one salesperson from a list of all salespeople and displays all of that salesperson's sales (invoices) in a table. We'll use an XiDBCombinationBox for the one-of-many choice.
Creating the Application
- Because Oracle is case-insensitive, the Schema Browser renders all names uniformly in uppercase.
Use the following steps to create the application:
- Create a bulletin board about 6 inches wide by 3 inches high.
- Select Combo Box from the Object Type option menu on the Schema Browser.
- Select Sales from the Tables list on the Schema Browser.
- Select the Employee_Id column from the Columns window on the Schema Browser.
- Using MB2, drag and drop the Employee_Id column onto the bulletin board. Your interface should now look like the figure shown below.
One Column Added as a Combination Box to the Interface
Setting Resources for the Combination Box
Enumerated widgets retrieve their choices from their XmNmap resource, in a way that is determined by the value of the XmNmapType resource. You will set XmNmapType to XiDB_MAP_SQL, which says that the XmNmap specifies an SQL statement that lists the choices.
- Locate the combination box widget (sales_Employee_Id) on the Browser hierarchy.
- Double-click on the sales_Employee_Id widget to update the Resource Editor.
- Find the map resource, located directly above the mapType resource.
- Set the map resource to "select Sales.Employee_Id,Sales.Name from Sales" (without the quotes).
The default setting for the map resource is XmNmap_Unset. The map resource has a text input field, so double-click on the default value and delete it to clear the input field.
The value of the widget is the first column--in this case, the employee ID. By specifying a second column, we are saying that the value in the second column (the name of the salesperson) should be displayed in the widget and then mapped to the first column value (for example, Employee_Id) if it is selected. We're doing this here so that we can select by name, but then use the corresponding Employee_Id in a join.
- Find the mapType resource in the Resource Editor.
This resource should be located directly below the map resource.
- Change the resource setting to XiDB_MAP_SQL.
By default, this resource is set to XiDB_MAP_STRING. Instead of a text input field, this resource presents an option menu of settings. Select XiDB_MAP_SQL from the option menu items.
All Possible Settings Displayed for mapType Resource
- Find the visibleItemCount resource.
By default, when you click on the arrow of the combination box you have created, only one choice will be displayed. The visibleItemCount resource determines how many items will be displayed when you click on the arrow.
- Enter "4" in the visibleItemCount input field.
The next step is to create the table.
Creating the Table
- Select Invoice from the Tables list in the Schema Browser.
- Select Table from the Object Type option menu in the Schema Browser. Drag the mouse through the Columns window to select all the columns.
- Drag and drop all the selected columns onto the bulletin board, below the combination box.
A table of the selected Invoice columns is created on your interface.
Although the combination box is connected to a query, you will not use that query in the search. The table acts as the query for the purposes of searching.
All Columns from Invoice Table Added to Interface as a Table
- Increase the height of the table by resizing the table, as you would any widget.
Either click on the dbTable object on the Browser hierarchy, or click on the table on the interface to select it.
Or use the mouse to resize the table. For example, use MB1 to drag the bottom edge down. The purpose of resizing the table is to display more data at once.
The table should now look like:
Setting Resources for the Table
Once you have created the table, the next step is to set resources for it:
- Find the table dbTable on the Browser hierarchy.
- Double-click on dbTable to both select it and update the Resource Editor.
whereinput field, enter "Invoice.Employee_Id = @value(sales_Employee_Id)" to set the
whereclause to retrieve only those invoices that correspond to the currently selected salesperson.
Testing the Application
You can now go into Play Mode and test the application:
- Click on the arrow button of the combination box to display the following three choices:
Combination Box Choices Displayed
- Select any customer name from the list. Note that the information now displayed in the table, as shown below:
Information Associated with Customer Name Displayed in Table