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):
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.
For most 4GL JSP pages, you should add scripts to handle initialization, response to page controls, and validation:
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:
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:
The following events are available on 4GL JSP pages:
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. |
psDocumentWrite 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.
4GL JSP pages also provide events for the various types of controls:
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.
To view a list of events available for a control:
On the Page tab page of the System Tree, click the name of the control.
Expand the item for the control, then expand its Events folder.