Responding to events on your page

An event-driven architecture is the foundation for working with 4GL JSP pages. Writing scripts to respond to server events controls the data that displays on your Web page.

Server events In the events list of the Script editor, server events appear in blue text. You must enable the 4GL Web server-side event model to display these events in the events list (a 4GL JSP page is required). When you write a script to handle an event, an icon identifies which events have associated scripts.

Server events for a page appear in the events list for the window object; server events for a control appear in the events list for a control object. Here the events list shows a partial listing of the server events available for the page (window object):

Shown is a drop down list box at left with window selected, then a drop down for on load ( ) showing a list of server events such as Request Start ( ) and First Time ( ), then a drop down list box for Java Script.

Client events You can also write scripts for client-side JavaScript events. Client events appear in black text in the events list. You do not need to enable the 4GL mode to write scripts for these events.

Summary of principal events for a page

For most 4GL JSP pages, you should add scripts to handle initialization, response to page controls, and validation:

Table 9-5: Typical server-side events to script on 4GL pages

To do this

Write a script to handle this event

Initialize page the first time a user visits it

FirstTime

For pages that use self-navigation, initialize a page on subsequent visits during the same user session

BeforeBinding

Respond to an action that a user performed using a page control (such as clicking a button)

ServerAction

Validate a page

Validate and ValidationError

Example 1: Initialize a page for a first visit Here the page retrieves the data about a user and displays it in the Web DataWindow dw_cart when the page initializes:

Shown is a drop down list box at left with window selected, then a drop down list with the entry First Time, then a drop down list box for Java Script. In the Script area below is the comment / / Retrieve user information and the line d w _ cart dot Retrieve ( user ) ;.

Example 2: Validate page If the ValidationError event is fired in response to a page validation error, the user sees the following message in an alert box:

Shown is a drop down list box at left with window selected, then a drop down list with the entry Validation Error (  ),  then a drop down list box for Java Script. In the Script area below is the comment / / Display message if there’s an error and the line p s Page dot Alert ( " Error processing page. Try again. " )  ;

Summary of optional events for a page

The following events are available on 4GL JSP pages:

Table 9-6: Server-side events for 4GL JSP page

This event

Occurs

RequestStart

At the very beginning of page processing, before server-side objects have been created and before any data binding or variable retrieval.

AfterBinding

After the controls have been bound to the input data and all validation has been done, but before any actions are performed.

BeforeAction

After data binding and validation and just before performing any action.

AfterAction

After all actions have been performed but before page generation.

BeforeGenerate

Before any generation happens. It is triggered both when the page is requested for the first time and when a self-navigation is done.

AfterGenerate

When all generation has taken place.

RequestFinish

After all generation is complete. It is the last event to occur on the page.

ServerError

When the ReportError method is called. It can be used to alert you when something goes wrong during processing.

NotepsDocumentWrite HTML generation occurs after the BeforeGenerate event. Do not place psDocument.Write in a script before this event. The appearance of the resulting page would be unpredictable.

Events for page controls

4GL JSP pages also provide events for the various types of controls:

Table 9-7: Server-side events for controls on a page

For these controls

These events are available

SingleLineText

Validate, ValidationError, ItemChanged

TextArea

Validate, ValidationError, ItemChanged

RadioButton group

ItemChanged

ListBox

ItemChanged

PushButton

ServerAction

CheckBox

ItemChanged

StaticText

ServerAction

DataWindow

AfterAction, AfterRetrieve, AfterUpdate, BeforeAction, BeforeRetrieve, BeforeUpdate, OnDBError, Validate, ValidationError

For a description of server-side events on Web DataWindows, see the DataWindow Reference. For a description of the server-side events on other controls on 4GL pages, see the Web and JSP Target Reference.

In addition to viewing the events available for a control from the events list in the integrated Script editor, you can expand a control on the Page tab page of the System Tree to see a list of events for that control.

StepsTo view a list of events available for a control:

  1. On the Page tab page of the System Tree, click the name of the control.

  2. Expand the item for the control, then expand its Events folder.