Try OpenEdge Now
skip to main content
Developing WebSpeed Applications
Controlling WebSpeed Transactions : Transaction control with HTML-mapping Web objects : Modifying the Main Code Block
 

Modifying the Main Code Block

The following is a copy of the Main Code Block that executes when you run an HTML-mapping Web object:
/* ************************* Main Code Block ********************** */
/*
* Standard Main Code Block. This dispatches two events:
* 'initialize'
* 'process-web-request'
* The bulk of web processing is in the procedure 'process-web-request'
* elsewhere in this WebObject.
*/
{src/web2/hmapmain.i}
The include file src/web2/hmapmain.i contains the default code that is executed each time a stateless Web object is run and the first time a state-aware Web object is run, as shown:
/* The CLOSE event can be used from inside or outside the procedure to */
/* terminate it. */
ON CLOSE OF THIS-PROCEDURE
  RUN destroy.
/* Now enable the interface and wait for the exit condition. */
/* (NOTE: handle ERROR and END-KEY so cleanup code will always fire. */
MAIN-BLOCK:
DO ON ERROR UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK
ON END-KEY UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK
ON STOP UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK:

/* Load the HTM handles etc. */
RUN initialize.
/* Process the current web event. */
RUN process-web-request.
END.
/* Run the local/adm-destroy procedures, if the procedure is ending. */
IF NOT THIS-PROCEDURE:PERSISTENT THEN RUN destroy.
This code first registers a call to the destroy event procedure as a SpeedScript trigger (ON CLOSE of the Web object).
Note: Initialization code is best done in a local initialize rather than changing the Main Code Block directly.
The default destroy procedure removes all traces of the Web object from memory. You can also override the destroy procedure to perform any other cleanup activities that you require before the Web object goes away. This is most useful in state-persistent applications to manage early termination of multi-page database transactions. For more information on database transactions, see Controlling Database Transactions.
The initialize event procedure performs a number of data assignments that are necessary before the Web object can execute. You can override this event procedure to add any one-time tasks that you require before process-web-request executes.
If you choose to add code directly to the Main Block before or after any initialization occurs and process-web-request executes, remember that this code executes only once for state-aware Web objects. Each additional time that the WebSpeed agent or another Web object executes a state-aware Web object using the run-web-object method procedure, only the process-web-request procedure is executed for the state-aware Web object until it times-out. When it times-out, the destroy event procedure is executed.