System Template
session.read()
Retrieves application data associated with the current session.
See Also
rb.page.session.write() Syntax
MetaData Object = rb.page.session.read(section)
Parameters
The 'session.read' method takes 1 parameter:
Name | Type/Value | Range/Length | Description | section | string | | Optional, default = data Name of the data section to readAvailable from version : 1.3.5 |
Results
The 'session.read' method returns a JavaScript object containing arbitrary attributes (Meta Value):
Type/Value | Range/Length | Description |
MetaData |
  | The JavaScript object containing the requested data set stored against this session.
|
Remarks Note: This method now takes an optional parameter identifying the session data section to read.
Previous versions had a single session data object. The advantage of multiple sections is that data can
be partitioned into separate application specific areas. For example authentication state can be stored separately to
temporary stored form data. This method allows the web designer retrieve data previously associated with
a session via the rb.page.session.write
For more details of the data format and how this method may be used please refer to
rb.page.session.write and
to the more general discussion on
application specific data. This method will always return a JavaScript object. If no data has been stored with the
session then the object will contain no properties. You cannot test for the presence of
session data by testing whether or not the result is undefined! Example This example reads the session data associated with authentication, checks for a 'userInfo' area and if not present creates
it. Finally it writes the modifications back to the system template so they are available the
next time the a page in the site is accessed.
<rb:script>
// Read any existing session data.
var sessionData = rb.page.session.read("auth");
// Check to see whether there is a 'user' object already.
if (!sessionData.userInfo) {
// No data - create it
sessionData.userInfo = {;
name:"Fred";
id:"44523";
}
// Finally store the session data ready for the next access.
rb.page.session.write("auth",sessionData);
}
</rb:script>
Note this is the recommended way of using session data.
- Read the current contents of the object.
- Make modifications for this page.
- Finally write the data back to the template.
|