Formula - formal syntax specifications
Introduction
The table grid editor allows for column values to be calculated from other columns. This functionality is based on the Apache Commons JEXL which is an open source Java Expression Language processor.
Additionally, the table grid editor adds
Expression validation
When an error is created in the configuration the administrator gets warned.Loop detection and avoidance
Formula's can reuse the values from other calculated columns. As this might create a loop (Column A depends on Column B and the way around), a configuration error is raised.
Check Formula - Examples for recipes to build formulas.
On this page
Literals
(Copied from JEXL Syntax)
Item | Description |
|---|---|
Integer Literals | 1 or more digits from 0 to 9, eg 42. |
Float Literals | 1 or more digits from 0 to 9, followed by a decimal point and then one or more digits from 0 to 9, optionally followed by f or F, eg 42.0 or 42.0f. |
Long Literals | 1 or more digits from 0 to 9 suffixed with l or L , eg 42l. |
Double Literals | 1 or more digits from 0 to 9, followed by a decimal point and then one or more digits from 0 to 9 suffixed with d or D , eg 42.0d. |
Big Integer Literals | 1 or more digits from 0 to 9 suffixed with b or B , eg 42B. |
Big Decimal Literals | 1 or more digits from 0 to 9, followed by a decimal point and then one or more digits from 0 to 9 suffixed with h or H (for Huge ala OGNL)) , eg 42.0H. |
Natural literals - octal and hex support | Natural numbers (i.e. Integer, Long, BigInteger) can also be expressed as octal or hexadecimal using the same format as Java. i.e. prefix the number with 0 for octal, and prefix with 0x or 0X for hexadecimal. For example010 or 0x10. |
Real literals - exponent support | Real numbers (i.e. Float, Double, BigDecimal) can also be expressed using standard Java exponent notation. i.e. suffix the number with e or E followed by the sign + or - followed by one or more decimal digits. For example42.0E-1D or 42.0E+3B. |
String literals | Can start and end with either ' or " delimiters, e.g. "Hello world" and 'Hello world' are equivalent. The escape character is \ (backslash); it only escapes the string delimiter |
Boolean literals | The literals true and false can be used, e.g. val1 == true |
Null literal | The null value is represented as in java using the literal null, e.g. val1 == null |
Functions
You can use functions on expressions such as
col.xyz.formula = math:round({price} * {discount} * {tax})
General functions
Function | Description |
|---|---|
empty | Returns true if the expression following is either:
empty(var1) |
size | Returns the information about the expression:
size("Hello") returns 5. |
Math functions
The table grid editor expression language also exposes all math functions such as
abs |
abs |
abs |
abs |
acos |
asin |
atan |
atan2 |
cbrt |
ceil |
copySign |
copySign |
cos |
cosh |
exp |
expm1 |
floor |
getExponent |
getExponent |
hypot |
IEEEremainder |
log |
log10 |
log1p |
max |
max |
max |
max |
min |
min |
min |
min |
nextAfter |
nextAfter |
nextUp |
nextUp |
pow |
random |
rint |
round |
round |
scalb |
scalb |
signum |
signum |
sin |
sinh |
sqrt |
tan |
tanh |
toDegrees |
toRadians |
ulp |
ulp |
String functions
These are the string functions as provided by the java.lang.String class.
When the containing column is of type 'string', the expression value will be truncated to 254 chars.
When applying a string function on a variable, you need to use the toString function to ensure that the variable is cast to a string.
A variable can contain a number.
For instance {product.name} .toString().toUpperCase() is required as {product.name} could resolve to a number
charAt |
|
compareTo |
compareToIgnoreCase |
concat |
contains |
contentEquals |
contentEquals |
copyValueOf |
copyValueOf |
endsWith |
equals |
equalsIgnoreCase |
format |
format |
getBytes |
getBytes |
getBytes |
getChars |
hashCode |
indexOf |
indexOf |
indexOf |