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”)


Total Salaries

Total Salaries

Total Active

Total Active

Further reading:


Using Groovy Expressions For Validation and Business Rules

ADF BC 11g Groovy expressions implicit type conversions

Introduction to Groovy Support in JDeveloper


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.
1 Comment so far

  1. Rage on January 15, 2013 5:07 am

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

Name (required)

Email (required)


XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Share your wisdom