To calculate the sum of a column (Number) or count the occurrence of a specific value, one could easily iterate and add (or count) the values. This however causes a considerable overhead and is often error prone.
Using Groovy expressions this can be implemented fast, easily and safely.
Consider the example were we have master-detail tables “Departments” and “Employees”. In the “Employees” table we have (among others) column “Salary” with number values and column “isActive” with “Y” or “N” values. If we need to display the sum of all salaries for a specific department (“Total Salaries”) and the number of active employees (“Total Number of Active”), we could simply calculate the two fields (as Transient attributes) in the Departments view object. For “Total Salaries” attribute in value type check “Expression” and in the value set: Employees.sum(“Salary”). For “Total Number of Active” attribute set value to Employees.sum(“isActive == ‘Y’ ? 1 : 0″)
Further reading:
Using Groovy Expressions For Validation and Business Rules
ADF BC 11g Groovy expressions implicit type conversions
Introduction to Groovy Support in JDeveloper
Comments
This entry was posted on Saturday, September 11th, 2010 at 3:11 pm and is filed under ADF. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.




I am new to adf, nice to see you as a bloger on this technology