Try OpenEdge Now
skip to main content
Developing WebSpeed Applications
Web Objects : A CGI Wrapper example

A CGI Wrapper example

The following shows an extract of the process-web-request procedure in the example CGI Wrapper Web object, w-forcst.w.:


PROCEDURE process-web-request :
  RUN output-header.

"<TITLE> Sports Customer List </TITLE>":U SKIP

/* Output your custom HTML to WEBSTREAM here (using {&OUT}). */
"<H1>Customer List</H1>":U SKIP
" <TH>Customer ID</TH>":U SKIP
" <TH>Customer Name</TH>":U SKIP
" <TH>Phone Number</TH>":U SKIP
"</TR>":U SKIP

FOR EACH Customer FIELDS(CustNum Name Phone) NO-LOCK:
{&OUT} "<TR>":U SKIP
" <TD ALIGN=LEFT>":U Customer.CustNum "</TD>":U SKIP
" <TD ALIGN=LEFT>":U Customer.Name "</TD>":U SKIP
" <TD ALIGN=LEFT>":U Customer.Phone "</TD>":U SKIP


This Web object is equivalent to w-sstcst.html, but instead of HTML it is written entirely in SpeedScript. The example shows a single procedure from w-forcst.w (omitting some comments) called process-web-request. (A procedure is a block of SpeedScript code that you execute by name using a RUN statement. Its capabilities are like those of procedures in Pascal or of subroutines in other languages.)
The process-web-request procedure is executed in every SpeedScript Web object that responds to a Web request and contains the main-line code for satisfying the request. Thus, process-web-request also functions as a method of the Web object. WebSpeed provides two different templates for process-web-request, one for CGI Wrapper Web objects and one for HTML-mapping Web objects.
Note: A method performs a generic action associated with an object, and is available to perform that action for all instances of the object. In WebSpeed, many procedures function like methods and are therefore known as method procedures.
Aside from being coded entirely in SpeedScript, the main functional difference between w-forcst.w. and w-sstcst.html is the process-web-request method procedure. This procedure allows a Web object to make itself state aware and thus manage state-persistent WebSpeed transactions. For more information on WebSpeed transactions and Web object states, see Controlling WebSpeed Transactions
In this case, process-web-request generates the entire Web page to satisfy the request, including all HTML and associated data. First, it runs the output-header procedure to generate the HTTP header for the page. It then reads the Customer table of the sample Sports2000 database (using the FOR EACH statement). It builds an HTML table listing the ID number, name, and phone number for each Customer record in the database table.
The end result is a tabulated list displayed as a page on the Web browser. It is identical to the output from w-sstcst.html that is shown in A simple query.
To create a CGI Wrapper Web object in the AppBuilder, you select CGI Wrapper in the File > New dialog box. A template comes up in the AppBuilder Section Editor. The code in bold text in w-forcst.w. shows all the code that you enter to create it. The code between quotation marks is plain HTML entered as SpeedScript character strings.
The {&OUT} symbol is WebSpeed syntax that initiates output to a Web page using a preprocessor variable. You can find the actual SpeedScript definition for OUT (the preprocessor name) in the install-path/src/web/method/cgidefs.i file installed with WebSpeed. This is an include file (source code file) shared by all Web objects. For more information about {&OUT}, see OpenEdge Development: ABL Reference.
A SpeedScript statement is always terminated by a period (.) or colon (:); so a period terminates each chunk of HTML started with the {&OUT} reference. The :U is a flag that tells the translation tool, Translation Manager, not to select this particular string for translation. The SKIP option begins a new line in the Web page. Notice the use of the tilde (~), the SpeedScript escape character, in the BGCOLOR attribute statement. The interior quotation marks are preceded by the escape character so they will not be misinterpreted as end quotes.