Problem: To display total of numeric columns in ADF table footer . Sometimes requirement is to display total of a numeric columns , for ex. Total of the salaries of all employees in a search.
Solution: Their are several ways this can be achieved , one of the ways is described in this blog How To add Table Footer Totals. This blog mentions to write the iteration code inside the getter of the footer transient attribute in viewRowImpl class , but if we have several attributes in table where we want to display the total in footer , above approach might be costly as iteration will be done per attribute. To avoid this we can use following approach.
1) Create a view object for your requirement and don't forget to generate Java classes .
5) Now go to viewRowImpl class and access the getter of variable defined in viewImpl class
from the getter of the footer total attribute. Please refer to below snapshot.
7) Now run the application , and you should see the footer total for the salary column.
You can add same for multiple columns if your use case requires to do the same.
Solution: Their are several ways this can be achieved , one of the ways is described in this blog How To add Table Footer Totals. This blog mentions to write the iteration code inside the getter of the footer transient attribute in viewRowImpl class , but if we have several attributes in table where we want to display the total in footer , above approach might be costly as iteration will be done per attribute. To avoid this we can use following approach.
1) Create a view object for your requirement and don't forget to generate Java classes .
2) Add a new transient attribute to your view object for storing "TotalSalary" . Create one new transient attribute for each field whose footer total needs to be displayed.
3) Define a variable for calculating the total in VOImpl class of the BigDecimal type. In case you have multiple attributes whose total needs to be displayed in footer , you need to declared variable for each attribute here.
4) Override executeQuery() method of ViewObjectImpl . Call super.executeQuery() , and then
call a method to calculate the totals and set it into the salaryTotal variable . Now we need to
create a secondary row set iterator, iterate through it and calculate the total of the salary attribute, don't forget to close the iterator :) . Here we can calculate total of multiple attributes in one go and set them to the variables defined for them in VOImpl class.
from the getter of the footer total attribute. Please refer to below snapshot.
6) For UI, create a query panel with table for your view object ( do not create a column for transient attribute) . Now inside the salary column , add footer facet with a binding of the transient attribute which was created for the footer total. You will need to add binding for the footer total attribute to the page definition file.
7) Now run the application , and you should see the footer total for the salary column.
You can add same for multiple columns if your use case requires to do the same.
Please download the application from here . Cheers :) .