Friday, November 2, 2007

Calculated Column in ADF Faces af:table Component

It happens that sometimes you need to implement calculated column in ADF Faces af:table column. Value for this column is calculated based on values in other columns. There could be many approaches to achieve this, as one of the most simple I can suggest to add calculated attribute into View object, on which af:table is based.

You can download developed sample application - This sample is based on standard HR schema available in Oracle XE database.

Calculated attribute can be added to View object in two steps:

1. Define new object attribute on View object, just provide name and type:

New attribute will be created as Transient:

2. Generate View Row Class for View object, just by selecting check-box in View Object Editor:

In generated class, edit getSalaryDiff() method and put needed logic here:

When described two steps are done, in Data Control calculated value becomes available and you can use it in your application User Interface layer:

Implemented sample application provides table with calculated value included - difference between maximal and minimum salaries:

When running sample application, don't forget to add adf-faces-impl.jar and jsf-impl.jar to application's WEB-INF\lib directory.


Frédéric Falliere said...

Hi Andrejus,

that paper is quite interesting.

What about one on calculated lines. Taking your examples, how would you implement a new line, at the end of the table, that will sum the 2 last attributes.

Interesting uh ?

ps : all samples downloads are dead.


Andrejus Baranovskis said...


It looks server is down, it will start to work after a while.

If you need sample for this post, drop me email, i will forward you.

Will be back to your question later today.


@shish @wasthi said...

But if i dont know np. of columns then how to add those.
My use case is i have to add Total of each row in a "SubTotal" and each time row may be increased or deleted then corresponding "Subtotal is displaye"..
How it can be possible
Thanx in Advance

@shish @wasthi said...

How can i add no. of columns that may be increased or decreased
Not fix

Andrejus Baranovskis said...

You need to use ADF Dynamic table.


Vladimir Klimov said...

Hi Andrejus,

Very nice paper, Thank you.

I have a question regarding refreshing value in calculated column.
In my case, I have a table of users with 'Groups' column showing comma separated list of groups for each user.
I use popup dialog to edit user records. User name refreshes after dialog is closed but 'Groups' column stay unchanged.
I tried placing popup and dialog inside Partial triggers for 'Groups' column but it did not help.
Could you please help me here?

Thanks in advance,

Andrejus Baranovskis said...


Try to re-execute iterator from dialog listener, may be transient attribute needs to be recalculated. Your calculated transient attribute is defined in ADF BC VO?