Using Groovy expression to create summary function in ADF

A common use case in master / detail pages is to display summary information in the master record about the details record

An example is the sum of employee salaries per department. In this tip, we will create a page based on dept/emp master details relationship and then display the sum of sal in the department record.  The solution is going to be based on Groovy expression in JDev 11g

In this example, the sum of salary will only be dispalyed and will not be based on database column.

Create an ADF project based on Dept/Emp with an association.

In the Dept View object, create an attribute called SumSal of type transient.

Set the Type to Number

Set the value Type to Expression (Radio button)

Set the value to adf.object.EmpView.sum("Sal");

as shown below and that is it.   To explain why we use EmpView in the expression

Please look at the XML source of the Dept View object (important part shown below)

adf.object refers to The current   ADF BC object

The EmpView is the accessor that coordinates the Master / Details relationship highlighted below.  This accessor is created automatically as part of ADF BC wizard when the viewlink is created

 

 <ViewAttribute

ame="sumsal"
IsUpdateable="false"
IsSelected="false"
IsPersistent="false"
PrecisionRule="true"
Type="oracle.jbo.domain.Number"
ColumnType="NUMBER"
AliasName="VIEW_ATTR"
SQLType="NUMERIC">
<TransientExpression>

   <![CDATA[adf.object.EmpView.sum("Sal");]]>

</TransientExpression>

</ViewAttribute>
 

<ViewLinkAccessor

Name="EmpView"
ViewLink="model.FkEmpDeptLink"
Type="oracle.jbo.RowIterator"
IsUpdateable="false"/>

 

Note, you can do the same on the Entity Level. The following is extracted from an example where the summary column is create as an entity attribute

 <Attribute
Name="EOsumsal"
IsQueriable="false"
IsPersistent="false"
ColumnName="$none$"
SQLType="NUMERIC"
Type="oracle.jbo.domain.Number"
ColumnType="$none$">
<TransientExpression><![CDATA[adf.object.Emp.sum("Sal");]]></TransientExpression>
</Attribute>
<AccessorAttribute
Name="Emp"
Association="model.FkEmpDeptAssoc"
AssociationEnd="model.FkEmpDeptAssoc.Emp"
AssociationOtherEnd="model.FkEmpDeptAssoc.Dept"
Type="oracle.jbo.RowIterator"
IsUpdateable="false"/>