Try OpenEdge Now
skip to main content
Developing WebSpeed Applications
Web Objects : HTML mapping examples : Complex HTML mapping that includes a SmartDataObject : Adding code
 
Adding code
After the HTML Mapping Wizard completes, you will see a tree view of an untitled Web object, which is similar to the following figure.
Figure 10. 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 OpenEdge Development: AppBuilder.
To complete the Web object:
1. 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:
Web.input
/*---------------------------------------------------------------------
Purpose: Assigns form field data value to frame screen value.
Parameters: p-field-value
Notes: This input trigger of the hidden field cusrowid sets the current
  row to the one in the hidden field to set the context in preparation
  for further processing.
---------------------------------------------------------------------*/
DEFINE INPUT PARAMETER p-field-value AS CHARACTER NO-UNDO.

DO WITH FRAME {&FRAME-NAME}:
setCurrentRowids (p-field-value).
END.
END PROCEDURE.
2. 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:
inputFields
/*---------------------------------------------------------------------
Purpose: Super Override
Parameters:
Notes: After standard behavior for this procedure, this procedure
override looks at a hidden field called AddMode, and sets a flag
indicating that this record is new, and must be created in the
database before the fields are assigned. The AddMode flag is then
turned off in preparation for sending the next page.
---------------------------------------------------------------------*/
  RUN SUPER.
  IF ab_unmap.AddMode:SCREEN-VALUE IN FRAME {&FRAME-NAME} = "YES" THEN
  DO:
    PleaseAdd = TRUE.
    setAddMode (TRUE).
  END.
  IF ab_unmap.AddMode:SCREEN-VALUE IN FRAME {&FRAME-NAME} = "NO" THEN
  DO:
    PleaseAdd = FALSE.
    setAddMode (FALSE).
  END.
  ab_unmap.AddMode:SCREEN-VALUE IN FRAME {&FRAME-NAME} = "NO".
END PROCEDURE.
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.
3. 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:
outputFields
/*---------------------------------------------------------------------
Purpose: Super Override
Parameters:
Notes: This outputs the current record to the hidden field cusrowid
before standard behavior for this procedure and outputs the AddMode
hidden field.
---------------------------------------------------------------------*/
  IF getUpdateMode() = "Add" THEN
    ab_unmap.AddMode:SCREEN-VALUE IN FRAME {&FRAME-NAME} = "YES".
  ELSE
    ab_unmap.AddMode:SCREEN-VALUE IN FRAME {&FRAME-NAME} = "NO".
  ab_unmap.cusrowid:SCREEN-VALUE IN FRAME {&FRAME-NAME} = getRowids().
  RUN SUPER.
END PROCEDURE.
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 OpenEdge Development: ADM and SmartObjects and OpenEdge Development: ADM Reference.
4. 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:
process-web-request
IF REQUEST_METHOD = "POST":U THEN DO:
    RUN inputFields.
    UN findRecords.
CASE get-field ("requestedAction"):
      WHEN "First" THEN
        RUN fetchFirst.
      WHEN "Next" THEN
        RUN fetchNext.
      WHEN "Prev" THEN
        RUN fetchPrev.
      WHEN "Last" THEN
        RUN fetchLast.
      WHEN "Search for Name" THEN DO:
        addSearchCriteria('name',get-value('searchname')).
        RUN findRecords.
      END.
      /* Maintenance action selected */
      WHEN "Save" THEN DO:
        IF getUpdateMode () NE "add" THEN
RUN fetchCurrent.
        RUN assignFields.
        setAddMode (FALSE).
        setUpdateMode ("").
      END.
      WHEN "Delete" THEN DO:
        RUN fetchCurrent.
        deleteRow().
      END.
      WHEN "Reset" THEN
        RUN fetchCurrent.
      WHEN "Cancel" THEN DO:
        RUN fetchCurrent.
        setUpdateMode ("").
      END.
      WHEN "Add" THEN DO:
        RUN fetchCurrent.
        setUpdateMode ("Add").
      END.
END CASE.