Using Uniface Default Cookies for State Management

Uniface's default cookie mechanism 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 as Cookie.

    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
       getitem/id Cookie, $webinfo("COOKIESIN"), "MY_VARLIST_COOKIE"
       getlistitems/id /component Cookie
    end; preActivate

    postActivate

    trigger postActivate
    variables  string WebServerCntxt, SessionId, Varlist
    endvariables  
       Varlist = $componentinfo($componentname, "VARIABLES")  
       putlistitems/id /component Varlist  
       putitem/id $webinfo("COOKIESOUT"), "MY_VARLIST_COOKIE", Varlist
    end postActivate
  2. In the server page, define the component variables.
  3. Use the component variables to keep the state information, the same as in non-web applications.

    The data assigned to the component variables are saved in the cookie with a key word MY_VARLIST_COOKIE when the postActivate trigger is fired. When next request arrives, the preActivate retrieves the data with the same key word as in the postActivate and loads them into the component variables. Therefore, the values of the component variables are preserved between each request.

Related Topics