Websydian v6.1 online documentationOnline documentation - Websydian v6.5

Valuespace Access



The Script Template generated by Websydian contains script code accessing the Valuespace object containing data values extracted from the back end part of the application.

This document will help you understand the generated script code which is necessary if you want to modify or enhance the code on the Script Template for special purposes.

Valuespace Data Structure

In order to understand how to access Websydian-generated Valuespaces, it is necessary to know the general data structure of a Valuespace object. 

See also the Virtual Template Structure section in the Scripting Background document giving an outline of how value spaces generated by Websydian are implemented within the Valuespace data structure.

Data Structure Overview

The data structure of the Valuespace object is outlined below (ASP implementation):

The Valuespace data structure contains 4 kinds of objects; Valuespaces/Subspaces, Value Collections, Subspace Collections, and Name/Value Pairs.  The entry to the Valuespace data is through the Main Valuespace object.

The different components in the Valuespace data structure is described below.

Valuespace/Subspace objects

A Valuespace (or a Subspace) is an object pointing to a Value Collection and a Subspace Collection.

The main Valuespace specifies the entry to the Valuespace data while each subspace in the Valuespace data structure is represented by a Valuespace object pointing to the underlying Value and Subspace collections.

Value Collections

A Value Collection contains a list of the values belonging directly to a Valuespace/Subspace.  The data values themselves are stored in Name/Value objects.

Subspace Collections

A Subspace Collection (or a Valuespace Collection) contains a list of the sub-Valuespaces belonging directly to a Valuespace.  Each entry in the Subspace Collection is a Valuespace itself.

Name/Value Pairs

Each individual data value contained in the Valuespace object is represented in the Name/Value Pair object.  The Name/Value Pair objects are pointed to by the Value Collection.

JSP Implementation

In the JSP implementation, the ValueSpace is stored in a more simple structure. The only object in JSP is the ValueSpace object. A ValueSpace object then embeds values and sub spaces where a sub space is a ValueSpace object. A value or a sub space can then be retrived by using the relevant methods on the ValueSpace object with the name of the value/sub space as the argument to the method.

E.g. a value is retrieved by using the GetValue(String) method on a ValueSpace object.

Access to Valuespace Data Structure

This section gives an overview of the different kinds of script code statements in the Script Templates generated by Websydian.

Variable Definitions

All variables used in the process of traversing the Valuespace data must be defined. 

Asp DIM NVS
Jsp ValueSpace NVS = null

Assignments

Assignments are used to set variables pointing to different locations in the Valuespace data structure.  The following kinds of assignments are generated by Websydian as part of the Script Templates:

Asp SET NVS = server.CreateObject("WebsydianScripting.NameValueSpace")
Jsp NVS = new ValueSpace(request);

The NVS variable specifies the main Valuespace and it is instantiated by the above statement.  This assignment is always specified once in the beginning of each generated Script Template.

Asp SET ChildX_NVS = Parent_NVS.Subspaces("ChildX")
Jsp ChildX_NVS = Parent_NVS.GetSubSpace("ChildX");

Sets the Subspace pointer to a specific subspace in the Subspace Collection belonging to a parent.  This kind of construct is used when having Parent Page Generators including Child Page Generators.

Asp Set X_VS = X_NVS.Values
Jsp X_VS = X_NVS;

Set a pointer to the Value Collection of a specific Subspace.  Data values can now be retrieved from the new variable.

Asp Set X_SpecificSubspaceVS = X_NVS.Subspaces("SpecificSubspace").Values
Jsp X_SpecificSubspaceVS = X_NVS.GetSubSpace("SpecificSubspace");

Set a pointer to the Value Collection of a specific Child Subspace under a Parent Subspace.  Data values can now be retrieved from the new variable.  The SpecificSubspace mentioned describes a possible 'system' subspace defined by Websydian (e.g. InternalFieldValues), see also the Virtual Template Structure section in the Scripting Background document.

Loop Constructs

Loop constructs are included in the generated Script Templates in order to traverse repeating structures in the Valuespace representing the data to be displayed in Grid rows.  The typical construct to traverse Grid rows are shown below:

Asp FOR EACH X_RowSS IN X_NVS.SubSpaces("WsyGrid").Subspaces
Jsp int X_NVS_row = 0;
ValueSpace X_RowSS_grid = X_NVS.GetSubSpace("WsyGrid");
while (X_RowSS_grid.ContainsSubSpace(String.valueOf(NVS_row+1))) {
  X_NVS_row++;
  X_RowVS = X_RowSS_grid.GetSubSpace(String.valueOf(NVS_row));
  X_RowSS = X_RowVS;

Inside the loop, the X_RowSS variable will point at the Subspace representing the individual Grid row.  The Grid rows will be traversed in the same order as they were created by the Page Generator.

Data References

ASP Implementation

Valuespace data references are generated instead of Replacement Markers when generating Script Templates with Websydian.  A data reference has the following format:

X_ValueCollection("Y_Field")

Data values can also be retrieved/qualified from the Valuespace directly instead of assigning variables for each step down the Valuespace structure, but this approach will result in specification of long and complicated Valuespace references, e.g.:

Having the following declarations:

SET Child_NVS = NVS.Subspaces("Child")
SET Child_InternalVS = Child_NVS.Subspaces("InternalFieldValues").Values

The following reference is valid:

Child_InternalVS("MyField")

Instead, the data reference could have been specified directly as:

NVS.Subspaces("Child").Subspaces("InternalFieldValues").Values
("MyField")

Jsp Implementation

Valuespace data references are generated instead of Replacement Markers when generating Script Templates with Websydian.  A data reference has the following format:

X_ValueSpace.GetValue("Y_Field");

Data values can also be retrieved/qualified from the Valuespace directly instead of assigning variables for each step down the Valuespace structure, but this approach will result in specification of long and complicated Valuespace references, e.g.:

Having the following declarations:

Child_NVS = NVS.GetSubspace("Child")
Child_InternalVS = Child_NVS.GetSubspace("InternalFieldValues");

The following reference is valid:

Child_InternalVS.GetValue("MyField");

Instead, the data reference could have been specified directly as:

NVS.GetSubspace("Child").GetSubspace("InternalFieldValues").GetValue
("MyField")

Dumping Contents of Entire Valuespace

During development and debugging, it may be necessary to see the entire contents of the Valuespace.  Valuespace and Subspace data contents can be dumped with the Dump() method, e.g.:

Asp NVS.Dump()
Jsp NVS._Dump()