Thursday, May 21, 2015

Groovy expression

Groovy expression
ADF Business Components utilize Groovy expressions to support scripting. Groovy is an open source, Java-like scripting language that can be stored in an XML definition file. For instance, the attribute name for the employee name Ename can directly be used in a Groovy expression to represent the value of the Ename attribute.
Groovy follows the same JavaBeans way of accessing the methods of an entity object that is defined in the Java class. Following are some of the ways to call the method of entity objects in a Groovy expression:
Java method Groovy expression
isEmployee() employee
getEmployee() employee
getEmpNo(int n) source.emp(5)
checkEmployeeName() source.checkEmployeeName()
checkEmployeeNo(int n) source.checkEmployeeNo(5)

Setting a default value
We can set a default value for an attribute in the entity or view object by using the Groovy
expression. The Default Value section for the attribute is provided with three options—Literal,
Expression, and SQL. For the Literal value, we can provide a literal value. The Expression option
is used to provide a value that is evaluated at runtime and to dynamically assign a default value
to the attribute.

For example, consider a case wherein we want to set a default value for the salary attribute
in the EmpEO.xml file based on the Deptno attribute. In this case, we have to provide an
expression that will be evaluated at runtime to provide the default value. The following steps
show us how to do this:
1. Click on the Sal attribute from the list of attributes displayed in the Attributes
section of EmpEO.xml.
2. In the Default Value section, select the Expression option. Now the pencil icon
will be enabled for the textbox below the Expression option.
3. Click on the pencil icon to open an Edit Expression Editor window, and add the
following code in the Expression editor box:
if(Job == 'MANAGER'){
Sal = 1000;
}
else{
Sal = 2000;
}




No comments:

Post a Comment