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: The trigger returns values in $status:
  • >=0—the requested operation is activated.
  • < 0—the requested operation and the postActivate trigger are not activated. The WRD will not respond with a specific error.
  • -21—the requested operation and the postActivate trigger are not activated. The WRD will respond with a Authorization failure.

In a web environment, the postRequest trigger is always activated, regardless of the value returned by the preActivate trigger in $status.

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 in $status.

The activation sequence of the preRequest, postRequest, preActivateand postActivate triggers in a web environment is shown in the following table:

Web-Specific Trigger Activation Sequence
preRequest return status preActivate return status exec or other operation postActivate postRequest WRD status
$status = -21 Not executed Not executed Not executed Not executed -21
$status < 0 Not executed Not executed Not executed Not executed 0
$status >= 0 $status = -21 Not executed Not executed Executed -21
$status >= 0 $status < 0 Not executed Not executed Executed 0
$status >= 0 $status >= 0 Executed Executed Executed 0

Triggers and operations are activated from left to right, depending on the $status returned by previous triggers.

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