State Triggers

Maintaining state information is an important aspect of developing web applications. Uniface provides state triggers to get and set state information, and to provide pre- and post-processing.

To avoid duplicating code in each server page, use the preRequest and postRequest triggers of a Uniface Server application shell for generic ProcScript. However, they use dedicated server processes, which may not always be desired.

The preActivate and postActivate triggers contain default code for maintaining state, although the code itself is different in DSPs and USPs.

State Management Triggers

Trigger

Level

Description

trigger preRequest Application This trigger is fired each time a server page is activated via the Uniface Web Request Dispatcher (WRD). It is used for user authentication, by checking $user and $password.

You can also use it to restore any database connections, if necessary, and for debugging and logging. It allows global pre-processing to be centralized in a single trigger.

trigger postRequest Application This trigger is fired after the server page has finished processing. It is used to close database paths, record log information, and write the message frame contents to the $webinfo output buffer to aid debugging.

It is only activated if the preRequest trigger returns a positive value in $status.

trigger preActivate Component This trigger is fired when the server page is activated, before the exec trigger is fired (which is before the browser displays the page). It is used to restore the state of a server page, either by retrieving previously stored state information contained in a cookie, or by retrieving this information from a database.

If the user context information does not conform to the requirements you have set (that is, if the ProcScript contained in the preActivate trigger returns a negative status), the component operation is not activated.

trigger postActivate Component This trigger is fired when processing in a server page completes. It is used to store state information, so that the state of a component can be restored, allowing further processing to be handled by a subsequent request to this component.

The postActivate trigger is fired before the postRequest trigger and before the instance of the component is deleted. It is the correct place to write ProcScript that is used to store user context information, that is, to write the current user context to a cookie or a database.

Related Topics