Whitebeam Template Reference Documentation

Site Map
 
Home
 
Application Guide
Reference
  Installation
  Configuration
  XML Markup
  JavaScript Classes
  ROM
  Templates
  Environment
  Dev Process
  Tools
  External Links
  Example libraries
Community
Contact Whitebeam
To-Do
Download
Credits
Licence
Whitebeam Users
 
 
 

Whitebeam Template Reference Documentation

System Template

session.write()

Stores application specific information against the current visitors session data

See Also

rb.page.session.read()   

Syntax

void = rb.page.session.write(section, SessionData)

Parameters

The 'session.write' method takes 2 parameters:

Name Type/Value Range/Length Description
sectionstring  Optional. The name of the section in which to store this session data

Available from version : 1.3.5

SessionDataMetaData  Required. The object to store in the session data. The is any arbitrarily complex JavaScript object

Results

The 'session.write' method returns no useful information.

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 to store application specific data against the current session. That information can be subsequently retrieved using the rb.page.session.read.

Note that calling this method over-writes any information currently stored against the session within this named section but will not change any data stored under a different section name.

Generally most common way of using the session data is to first read the current contents of a section (which may be empty), make modifications to the object and then write that section's data back to the system. In this way each page can store information against session without loosing any information being stored by other areas of the application.

It is recommended for complex applications that the session data object be partitioned into a number of separate silos identified by section name. So for example:

'user'Stores information about the user. Eg during a sequence of user registration forms.
'basket'Simple data representing accumulated shopping information.
'prefs'Session preferences.

This method will always return a JavaScript object. If no data has been stored with the session for the requested section name 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, checks for a 'userInfo' are 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.
Whitebeam release 1.3.36
(loadtime : 62ms)