Adding scripts to 4GL JSP pages

The extensions to the Web Target object model give you other ways to customize a page by writing scripts to access:

Properties and methods of the psPage object

The psPage object represents an entire 4GL JSP page. You can add properties as well as methods for the psPage object to your page by dragging them from the System Tree, dropping them into the appropriate place in the Script editor (or in Source view of the HTML editor), then defining arguments.

For a list and description of psPage properties and methods, see the Web and JSP Target Reference.

All psPage methods (except Redirect) help fine-tune error reporting for your page. The psPage Alert method lets you display a client-side Alert box to make sure that users of your Web application see important messages. If you use the Alert method to inform users about validation errors, it lets them correct entries that are not in the correct syntax.

Here is how you can use the Alert method in a script in response to a ValidationError event:

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. " )  ;

Adding scripts for properties of controls

Objects for controls also have associated properties that you can access in server-side scripts:

Table 9-8: Typical properties for controls on a 4GL JSP page

Property

Description

name

The name of the control. This is a read-only property.

value

The label for the control.

visible

Sets whether or not the client control is generated. If not visible, there is no access to the client control.

enabled

Sets whether or not the control allows focus. (This property works only in browsers that support the DISABLED attribute.)

Typically you set values for object properties on the property pages for the control rather than in server scripts.

Using the psPage prefix

When referring to read-write variables in script for client-side events, it is best to include the psPage prefix before the variable name. Otherwise, client-modified values might not be passed on to a target page; initial values are passed if the prefix is not included in the script. Page parameters cannot be accessed in client-side script. You can optionally use the psPage prefix for the names of controls on the page.

Example 1: Client-side code This script in a client-side onchange event sets the v1 read-write variable to a value the client enters in the sle_1 text box (an alert message should not be prefixed with psPage on the client side):

alert("This is the client-side onchange event");
psPage.v1=psPage.sle_1.value;

Example 2: Server-side code This same script in a server-side event (such as ItemChanged or ServerAction) should omit the references to psPage, except for code that calls methods on the server page object:

psPage.Alert("This is a server-side event");
v1=sle_1.value;

For more information on scripting, see Chapter 6, “Writing Scripts” and Chapter 7, “Working with Application Servers and Transaction Servers.”