First page Back Continue Last page Graphics


Using Groovy Syntax in ADF (continued)

Transient Attribute: The context is the current entity or view row. You can reference all attributes by name in the entity or view row in which it appears, as well as any public method on that entity or view row. To access methods on the current object, you must use the adf.object keyword to reference the current object like this: adf.object.yourMethodName(). The adf.object keyword is equivalent to the this keyword in Java. Without it, in transient expressions the method is assumed to exist on the dynamically compiled Groovy script object itself.

Expression Validation Rule: The context is the validator object (JboValidatorContext) merged with the entity on which the validator is applied. You can reference keywords such as:

newValue, in an attribute-level validator, to access the attribute value being set

oldValue, in an attribute-level validator, to access the current value of the attribute being set

source, to access the entity on which the validator is applied in order to invoke methods on it (accessing simply by using attribute values in the entity does not require using the source keyword)

All Java methods, language constructs, and Groovy language constructs are available in the script. Some additional tips to keep in mind:

You can use built-in aggregate functions on ADF RowSet objects by referencing the functions sum(), count(), avg(), min(), and max(). They accept a string argument, which is interpreted as a Groovy expression that gets evaluated in the context of each row in the set as the aggregate is being computed: rowSetAttr.sum("GroovyExpr") such as employeesInDept.sum("Sal") or employeesInDept.sum("Sal!=0?Sal:0 + Comm!=0?Comm:0") rowSetAttr.count("GroovyExpr") rowSetAttr.avg("GroovyExpr") rowSetAttr.min("GroovyExpr") rowSetAttr.max("GroovyExpr")

Use the return keyword just like in Java to return a value, unless it’s a one-line expression in which case the return is assumed to be the result of the expression itself (such as Sal + Comm or Sal > 0).

Use the ternary operator to implement functionality that is similar to SQL's NVL() function. For example: Sal + (Comm != null ? Comm : 0)

Do not use { } to surround the entire script. Groovy treats { as a beginning of a Closure object (see Groovy documentation for more on Closures.)

Any object that implements oracle.jbo.Row, oracle.jbo.RowSet or oracle.jbo.ExprValueSupplier is automatically wrapped at run time into a Groovy “Expando” object to extend the properties available for those objects beyond the bean properties. This enables easy reference to ADF row properties (even if no Java class is generated) and avoids introspection for most used names.