Elixir Report Designer supports JavaScript 1.6 as standardized by the European Computer Manufacturer's Association(ECMA) as ECMA Script version 3. This document details some of the features of JavaScript and their use within the Report framework.
In Elixir Report Designer, scripts are always rendered in the order that the bands
appear in the output. Within a band, scripts in RenderIf
will be
rendered first. It will be followed by OnRenderBegin
,
OnRenderEnd
, then OnLayout
. As for the
element(s) in each band, scripts of each element will run in the order the elements
appear in the Shapes
tree (Z-order).
JavaScript is a weakly typed, object-based scripting language modeled on Java syntax. It is a case-sensitive language and the following key-words are reserved. It is a case sensitive language and the following keywords are reserved.
Table 6.1. JavaScript Keywords
break | else | instanceof | true |
case | false | new | try |
catch | finally | null | typeof |
continue | for | return | var |
default | function | switch | void |
delete | if | this | while |
do | in | throw | with |
Three primitive types are available: Numbers, Booleans and Strings, along with two compound types: Objects and Arrays.
Numbers in JavaScript are represented internally using 64-bit floating point values - there is no integer type. Numbers may be written in decimal form: 10, 20.5, 30, exponent form: 3e-2 or hexadecimal: 0xFF.
JavaScript supports all conventional mathematical operators, including +,-,*,/ and % (modulus). The Math object provides additional functionality, such as sqrt, power, sin, cos, tan etc. Certain operations may yield errors with invalid input, for example Math.sqrt(-1) produces the result NaN - a special value which indicates the result is Not A Number.
The Boolean type has two values: true and false. Boolean can be used as a function: Boolean(x) where the result is true unless x is 0, NaN, null, undefined or "" (the empty string).
The String type represents a sequence of characters and is delimited with either single or double quotes: "Hello World", 'Elixir Report'. Strings can be concatenated with the + symbol:
"Hello " + "World"
Other types are automatically converted to Strings when concatenated with them:
count = 5; message = "Hello" + count
This example also shows that multiple statements are separated by semi-colons. Strings support many additional functions, including: length, charAt, indexOf, match, replace, split, substring etc. Strings in JavaScript are immutable - just like in Java - once created they cannot be changed.
Objects are compound types because they can contain multiple properties (named values of any type). Elixir Report Designer provides objects which represent all of the components that can be manipulated through the Report Designer. Most use of scripts in Elixir Report Designer consists of manipulating the properties of these objects during the report rendering process.
Where JavaScript is used to access Java objects, it is possible to use two alternate forms of access. You can access properties through traditional get and set methods, or access the properties directly, which JavaScript then translates into the appropriate get and set operations. For example, these two lines have identical behaviour:
component.setBackgroundColor("Red"); component.backgroundColor = "Red";
A similar situation applies for get:
c = component.getBackgroundColor(); c = component.backgroundColor;
You can choose the style of property access that suits you.
Objects loaded from a datasource may sometimes have field names that are not valid names in JavaScript. Such fields can still be accessed by using a named lookup of the value. For example, if the field name is 2000 (which obviously isn't a valid variable name) you can access the value with
this["2000"]
Arrays are compound types which contain indexed values of any type. An array is created using the new keyword:
a = new Array(10)
This allocates ten slots in the array named a, that are indexed a[0] - a[9]. Arrays can also be created with initial values using an alternate syntax:
a = ["Hello", "World", 123 ]
This creates an array named a with three slots, where a[0] is the string "Hello", a[1] is the string "World" and a[2] is the number 123.