WebSpeed
Developer’s Guide
Complex HTML Mapping That Includes a SmartDataObject
Figure 4–7 shows the Web page generated by another sample WebSpeed application,
w-custdir.w
.Figure 4–7: Web Page Generated from w-custdir.w
![]()
The Web page shown in Figure 4–7 interacts with the Customer table of the Sports2000 database like the other examples in this section. However, it also has the ability to add or change records in the table. Moreover, it uses a SmartDataObject to define its query logic. The following sections describe these features in more detail.
Creating a SmartDataObject
SmartDataObjects provide query logic that is separate from the rest of your application. As separate modules, they can be used by multiple applications, can be refined at run time, and can be modified more easily than queries that are embedded within applications. Another advantage to SmartDataObjects is that they can be used on an AppServer for multi-tier deployment. See Building Distributed Applications Using the Progress AppServer for more information.
SmartDataObjects can easily be created in the AppBuilder. The SmartDataObject associated with
w-custdir.w
is calleddcustomer.w
. You can create it by performing the following steps:
- Choose File
New from the AppBuilder main menu.
The New Object dialog box appears:
![]()
- Select SmartDataObject from the list of SmartObjects.
Note that AppBuilder must be connected to a database in order to create a SmartDataObject. The procedures for starting and connecting to a database are described in Getting Started with WebSpeed .
- Choose Next on the SmartDataObject Wizard, then choose Define Query from page 2 of the wizard.
- In the Query Builder:
- Go to the next dialog box in the wizard (page 4) and choose Add Fields.
- Choose Add and add all of the available fields to the Selected Fields list.
- Go to the final page of the wizard and choose Finish.
You will see a window labeled Untitled, which represents the SmartDataObject you just created. You can save it as
dcustomer.w
from the File menu of the AppBuilder.When you save a SmartDataObject, you create a number of files: .w, .r, _cl.w, _cl.r, and .i. For more information about the function of these files, or for more information about SmartDataObjects in general, see the Progress ADM 2 Guide and the Progress ADM 2 Reference.
For more information about creating SmartDataObjects with the AppBuilder, see the Progress AppBuilder Developer’s Guide.
Mapping With a SmartDataObject
You can specify
dcustomer.w
as the data source when you use the HTML Mapping Wizard to map an HTML file likew-custdir.htm
:
You can use the HTML Mapping Wizard’s Automap feature to map the fields referenced in
w-custdir.htm
to the database fields referenced indcustomer.w
. Note that all the fields will map except the hidden fields and the SearchName field (shown in bold). These fields are used to pass information to the WebSpeed Agent and do not reference fields in the database.The hidden field, cusrowid, holds a value that identifies the current record that is displayed on the Web page. It establishes a context for the WebSpeed Agent when the next request is submitted. The other hidden field, AddMode, holds a value that tells the WebSpeed Agent if a new record is to be added or not when the next request is submitted. The code that utilizes these hidden fields is explained in the following section.
Adding Code
After the HTML Mapping Wizard completes, you will see a tree view of an untitled Web object, which is similar to Figure 4–8.
Figure 4–8: Tree View of an Untitled HTML-mapping Object
![]()
From the Code Sections branch of the tree view, you can add all the code that is necessary to complete
w-custdir.w
. With Code Sections selected, choose the Edit Code button from the AppBuilder Tool Bar to start the Section Editor. The Section Editor allows you to add new procedures, to modify default procedures, and to invoke and override super procedures. For more information, see the Progress AppBuilder Developer’s Guide.You will need to do the following in order to complete the Web object:
- Create a trigger that responds to the value of cusrowid.
In the trigger, the value of cusrowid is passed to the setCurrentRowids procedure. Recall that the value of cusrowid is stored in a hidden field and is set in a prior WebSpeed transaction. The trigger essentially tells the WebSpeed Agent which row in the table to refer to. In other words, the trigger establishes a context for the WebSpeed Agent by passing information about a previous transaction.
In the example Web object, the trigger is called Web.input and the code looks similar to the following:
- Create a procedure that responds to the AddMode flag.
In the example Web object the procedure is called inputFields and the code looks similar to the following:
As noted in the comment, this procedure is actually an override to the inputFields super procedure. This override supplements the standard behavior of inputFields by allowing it to react to the value of the AddMode flag in the hidden field. This code allows the Web object to add a new record to the database.
- Create a procedure that manages the unmapped fields.
In the example Web object, the procedure is called outputFields and the code looks similar to the following:
As noted in the comment, this procedure is actually an override to the outputFields super procedure. Its purpose is to identify the correct row for the next transaction. This override sets the value of ab_unmap.custrowid to the rowid of the current record. The value of ab_unmap.custrowid is set before running outputFields.
The ab_unmap temporary table holds the values of the fields that are unmapped. In this example, the unmapped fields are cusrowid, SearchName, and AddMode.
NOTE: The AppBuilder online help contains reference pages that describe the syntax and behavior inputFields, outputFields, and all other super procedures that apply to WebSpeed. For more information about using super procedures, see the Progress ADM 2 Guide and the Progress ADM 2 Reference.- Modify process-web-request so that the Web object responds to button events.
The button events are handled in a case statement, as shown in the following segment:
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |