trigger preActivate

System trigger that provides component-specific pre-processing. It is required in web applications to recreate the component state.

Declaration: trigger preActivate
Applies to: All components
Activation: Activated before a requested operation is activated, and in a web environment, after the postRequest trigger.
Default behavior:

Sets return 0

For dynamic and static server pages, default code is provided to restore component state and load data into the component

Behavior upon completion:

If the trigger returns 0 or a positive value, the exec operation or the requested operation is executed.

If the trigger throws an exception or returns a negative value, additional information is added to $procerrorcontext, the requested operation and the postActivate trigger are not activated.

In a web environment, the postActivate trigger is always activated, regardless of the value returned by the preActivate trigger.

Description

The preActivate trigger is typically used to handle preprocessing specific to the operation, such as recreating the state of a transaction. Although it is required in web applications, it can also be used in other components to handle preprocessing that is specific to the component.

preActivate in Server Pages

Default ProcScript is provided for dynamic and static server pages, which enables you to tailor component behavior based on the state management options you use.

In a web environment, it can mean reading cookie data or information stored in a database. For example, of the state information is no longer current, further processing can be terminated by returning a non-zero value.

Getting and Setting State with Cookies

The following example gets the Uniface cookie from the browser and places it in the $cookie$ component variable. The USERCONTEXT information is stored as an associative list in the format Variable=Value, where Variable is the name of a field or variable in the server page. The getlistitems/id statement reads the values contained in $cookie$ and distributes them accordingly:

trigger preActivate
   $cookies$ = $webinfo("USERCONTEXT")
   getlistitems/id/component $cookies$
end; preActivate

In the postActivate trigger of the static server page, the following code updates the state information when the page completes. The ProcScript in this example initializes a component variable $statelist$ with the names of the fields or variables containing the state information, then uses the putlistitems/id statement to populate the list in $statelist$ with the current values from the server page:

trigger postActivate
   $statelist$ = "Variable1=;Variable2="
   putlistitems/id/component $statelist$
   $webinfo("USERCONTEXT") = $statelist$
end; postActivate

If you put empty cookie data into the first item of USERCONTEXT, for instance, by using putitem $statelist$, 1, "", followed by $webinfo("USERCONTEXT") = $statelist$, Uniface substitutes a NULL identifier at the moment the empty cookie data is sent to the client.

Related Topics