TMLScript globals V1
TMLScript globals are special variables that are automatically available to a wide range of TMLScript code across all requests and sessions.
Normal TMLScript globals are available to all TMLScript code of the complete OpenWGA runtime. They are dedicated tools to enhance the language capabilities of TMLScript with new features that should be globally available.
So called TMLScript DB globals are available to all TMLScript code of a single OpenWGA application. They are usable to provide resources that are needed across all code of that application.
An OpenWGA design can define TMLScript globals that may contain one of these four artefacts:
- A Java Package for easily referencing classes inside this package
- Any Java object
- Any TMLScript object, including Custom TMLScript objects
Because of their scope TMLScript globals should always contain resources that are meaningful for the whole application or runtime, not for single users or sessions. Also they should not keep references on resources which are valid only for special requests oder sessions, like TMLContext objects, TMLForms, TMLPortlets or TMLUserProfiles.
TMLScript globals have case-sensitive names that follow strict naming rules to avoid collisions with other TMLScript qualifiers:
- The name must begin with an uppercase letter
- The name must not equal the name of a WebTML metadata field
TMLScript globals can be registered in two ways:
Otherwise it is possible to register TMLScript globals directly from TMLScript. Use method Design.registerGlobal() for normal globals and Design.registerDbGlobal() for db globals. Both methods take the global name and the resource to store as global for arguments:
It is recommended to register globals in the connect script of an application (see Tab "Design Configuration"). The registration of TMLScript globals from script running on behalf of WebTML pages is discouraged, as this promotes inappropriate usage with user/session bound resources.
TMLScript globals are available to the TMLScript code of their scope just by using their name in exact case. The contained resource then can be used just like it would have been addressed in its normal form:
So when registering a Java package:
Then the following code can be used to access Java classes contained in the package. Here by using a static method on class "de.innovationgate.webgate.api.WGFactory":
var wgapiTempDir = WGAPI.WGFactory.getTempDir();
An example storing a Java object in a DB global:
var appContext = new Packages.de.innovationgate.myapp.ApplicationContext();
The object then can be used under name "AppContext" in all TMLScript code of the application:
The same is possible for a TMLScript object:
var dbm = WGA.createObject("objects:dbm");