A session variable is a name-value pair maintained for the duration of the session by the GAS. A session variable is accessible from the user agent, the application, and the GWC snippet-based rendering engine.
In order to make a session variable persistent between two runs of an application, you must store the session variable in an HTTP cookie. The cookie is a text-only string containing the name-value pair and is saved into the memory of your browser. The cookie is then sent back to the GAS on all future requests for the application.
Create, Set, and Get Session Variables and HTTP Cookies
A session variable or cookie can be created and updated in the following ways:
Every session variable may not need to be put into an HTTP cookie; conversely every HTTP cookie value need not be put into a session variable.
The idea is to tag each session variable that has to be set into a cookie. The snippet-based rendering engine (with the GAS) would be in charge of maintaining the cookies/session variables synchronization. On incoming HTTP requests, the engine would update corresponding session variables; on outgoing HTTP responses, the engine would set changed cookies. Between the request and the response, the 4GL developer can update session variables. Therefore, updating an HTTP cookie is indirectly done by updating its session variables.
The main goal of cookies is to keep a state, through session variables, between two runs of an application by the same user. The number of cookies associated with an application should be constant.
You declare cookies for an application within the configuration file.
<!-- session cookie --> <HTTP_COOKIE Id="cookie1"> <VARIABLE Id="var1" /> <VARIABLE Id="var2" /> <VARIABLE Id="var3" /> <VARIABLE Id="var4" /> </HTTP_COOKIE>
<!-- persistent cookie that applies only to this application --> <HTTP_COOKIE Id="cookie2" Expires="date" Domain="domain"> <VARIABLE Id="var5" /> <VARIABLE Id="var6" /> </HTTP_COOKIE>
<!-- secure persistent cookie with default variable value and constant value --> <HTTP_COOKIE Id="cookie3" Expires="date" Domain="domain" Secure="TRUE" HttpOnly="TRUE"> <VARIABLE Id="var7" /> <VARIABLE Id="var8">Initial value</VARIABLE> <CONSTANT Id="constant1">A value</CONSTANT> </HTTP_COOKIE>Note: All cookies and all associated session variables will be shared between all applications.
A set of front-end functions allows you to dynamically set and get session variables from within your Genero application. These front-end functions are:
Note: Setting a variable to an empty string is equivalent to deleting the variable.
makeSessionVarIDID(varName, varValue)
In the template itself, you would add this function using a line such as the following:
<input type="hidden" gwc:attributes="name makeSessionVarIDID('var1','value1')" />
Note: Setting a variable to an empty string is equivalent to deleting the variable.
gwc.capi.SessionVar(varName, varValue)
In the template itself, you would add this function using a line such as the following:
<input type="button" onclick="gwc.capi.SessionVar('var1','value1')" />
Note: Setting a variable to an empty string is equivalent to deleting the variable.
application/meta/variables application/meta/variable[<name>] application/meta/variable/XDID application/meta/variable/name application/meta/variable/value application/meta/variable/readOnly
See also: The ApplicationMetaInformation object and The Variables object (part of Template Paths - Application Hierarchy)