问题
I very new to Oracle ADF.
I have created a view object and it has a transient attribute. (Select literal and provided no value.) Now I want to populate the column using another column of the same viewobject(some business calculations are there) from a Java class. Any idea which class or how I can do that?
Is it rowImpl class that I have to write my logic? If so can you give an example?
here is an example of what I am looking to create. in Hr schema we have Department and Employees table liked with foreign key relationship.
DepartmentName Noofemployees Percentage
HR 2 10.52631579 Admin 8 42.10526316 Engineer 9 47.36842105 Grand totatal 19 100
here percentage is my transient attribute. So value is 2/19*100 OR 8/19*100 ,etc
回答1:
Why not consider Groovy for calculating the value of the transient attribute by setting it to "expression" then writing a Groovy expression to refer to the other attributes in the same VO. Using Groovy Whitepaper Webinar Sample Docs
回答2:
Solution: In departments VO create a transient attribute "TotalEmployees" with the following expression : EmployeesView.count("Employee_id") this gives you a count of employees in each department. Now in DepartmentsView.xml create a view accessor , add DepartmentsView. Thus now u can access each row of the same view with this accessor. Create another transient attribute named "Percentage" In the expression write the following code:
if(TotalEmployees == null){
return TotalEmployees}
else {
return TotalEmployees/DepartmentsView.sum("TotalEmployees")*100
}
Note: null condition is to avoid div by null value exception.
回答3:
you can let jdev create the ViewRowImpl class which will give you geetter and setter methods for the attributes. in the get of your transient attribute you implement you calculations and return the result.
来源:https://stackoverflow.com/questions/15584850/java-code-to-populate-an-transient-attribute-in-oracle-adf