OpenWGA 7.0 - TMLScript reference


Object:

table

Description A lookup table is a collection of objects which are stored under individual keys. The keys then can be used to retrieve the object that was stored under that key, i.e. "looked up".

A pair of key and value (the object to store) in a lookup table is named "element".  A key can only be used by one element in a lookup table. A special value in contrary can be contained in many elements if it is stored under differing keys.

To read the value of an element from the table use table.get with the key of the element. To create or update an element with a new value use table.put with key and value as parameters.

Keys and values of a lookup table may technically be any type of object, but mostly trivial objects like strings or numbers are used as they can be easily compared and reproduced. String keys are case sensitive. You can store different elements under keys "Key", "key" and "KEY".

To iterate over all existing elements of a table you can use global function WGA.getLookupKeys() to retrieve all its keys, which you then can use to retrieve all element values.

Native JavaScript objects can be used instead of lookup tables everywhere a lookup table is expected. The property names of objects will be taken as lookup keys while the property values will be  taken as table values.

From a Java perspective lookup tables are just the TMLScript view of Java interface java.util.Map

Retrieval

Via many methods, but mainly by:

WGA.createLookupTable()

Allowed in script types
  • WebTML pages and normal WebTML actions
  • Master actions
  • TMLScript tasks in jobs
  • Content type events
    portletevent
Properties and methods
Name Purpose
clear() Removes all elements from the table
containsKey(key) Tests if the table contains an element with the given key
containsValue(value) Tests if an element with the given value exists
get(key) Reads the value of the element with the given key
isEmpty() Tests if the table is empty
put(key, value) Creates or updates an element of the given key with a new value
putAll(table) Adds all elements of the parameter table to this table
remove(key) Removes the element of the given key from the table
size() Returns the number of elements on the table
Examples

This example creates a table and fills it with month numbers as keys, storing the corresponding month name as values:

months = WGA.createLookupTable();
months.put(1, "January");
months.put(2, "February");
months.put(3, "March");


Such a table could be used in WebTML code to lookup month names by their numbers: using the get() method:

The month is <tml:script expression="months.get(monthnr)"/>

(Note that this is not really a recommendation for storing month names but only a demonstration of map usage. Month names can and should be generated just by formatting dates with approprate formatting rules)