OpenWGA 7.5 - OpenWGA Concepts and Features

Design and development » TMLScript

Basic data types

The basic data types of TMLScript are generally the same of JavaScript, having objects of type String, Number and Boolean.

There is one exception though: The object Date. While TMLScript knows the JavaScript Date object (instantiable viw "new Date()") its use is discouraged for the following reasons:

  • It is not recognized as a date value when stored to an OpenWGA content store, therefor its date information is not usable in database queries
  • It does not work with the methods of the base objects in OpenWGA
  • Missing localisation support

Instead TMLScript uses the Date object from Java to represent date values. There are several convenience methods to work with it:

  • WGA.createDate() to create date objects, initialized with the current time
  • WGA.parseDate() parses out a date value from a string in a given format
  • WGA.createCalendar() creates a calendar object which is used to modify date values in a controlled manner
  • WGA.format() puts out a date value as a string in a given format

It is possible to convert the JavaScript types String, Number and Boolean to the corresponding Java classes. This may be helpful if you need a method that only the Java pendant of the data type provides. Use method WGA.javaObject() to do this.

The following example converts a JavaScript string to a Java string in order to use the method "trim()" on it, which is not available on the JavaScript string:

javaObject("   A String to be trimmed    ").trim()