Using Default Temporary Tables to Maintain State

Uniface provides an automatic temporary-table mechanism for you to maintain state. It makes use of the default ProcScript supplied in the preActivate and postActivate triggers.

  1. In the server page properties, set the State Managed by property to State manager component.

    The pre-defined code in the preActivate and postActivate triggers results in the following runtime code:

    preActivate

    trigger preActivate
    variables  
       string WebServerContext, Cookie, Session, UserContext
    endvariables
       WebServerContext = $webinfo("WEBSERVERCONTEXT")  
       getitem/id Session, WebServerContext, "SESSION"  
       UserContext = ""  
       activate "USYSSTAT".GetState(Session, $instancename, UserContext)  
       getlistitems/id /component UserContext
    end; preActivate

    postActivate

    trigger postActivate
    variables  
    string WebServerCntxt, SessionId, Varlist
    endvariables
       WebServerCntxt = $webinfo("WEBSERVERCONTEXT")  
       getitem/id SessionId, WebServerCntxt, "SESSION"  
       Varlist = $componentinfo($componentname, "VARIABLES")  
       putlistitems/id /component Varlist  
       activate "USYSSTAT".SetState(SessionId, $instancename, Varlist)
    end; postActivate
  2. In the server page, define component variables.
  3. Use the component variables to keep the state information.

    The data assigned to the component variables are stored in the UComponentVariables.USTATE field when the postActivate trigger is fired. When next request arrives, the preActivate trigger retrieves the data and loads them into the component variables. Thus, the values of the component variables are preserved between each request.

Related Topics