Oracle Adf Tricks

Only available on StudyMode
  • Topic: JavaScript, Pop-up ad, JavaServer Faces
  • Pages : 13 (3632 words )
  • Download(s) : 171
  • Published : April 13, 2013
Open Document
Text Preview
Creating a dynamic (AJAX) Column Footer Summary in a Table Component using ADF Faces One fairly common requirement for web applications is the display of Summary fields with calculated values. An obvious example is a table of multiple records with column-summaries appearing underneath the table. Using ADF Faces technology, it is fairly simple to quickly develop an application that presents a multi-record layout based on data retrieved from a database. In this article we will see how we can add a summary column to the columns in such a table layout – and to make those summaries automatically updating when a value for one of the records in the table is changed in the specific column.  

 
Creating the master-detail application
The application I use for this example is a well-known one: a Master-Detail (form-table) page for DEPT and EMP. For each Department, we will see the details in a Form layout with underneath a Table component with all Employees in the Department. Using JDeveloper 10.1.3, ADF BC, ADF Binding (Framework) and ADF Faces, creating such a page is almost trivial, especially if you generate it using JHeadstart 10.1.3 (which is what I did here). In quick summary the steps: 1. Create new Application, choose Web Technology (ADF BC and JSF) as Technology Template; Model and ViewController project are created automatically 2. Create Business Components from Tables EMP and DEPT in SCOTT schema in the Model project; add View Link from Source DeptView to Target EmpView 3. Using JHeadstart: enable JHeadstart on the ViewController project, create default Application Definition file, generate the application 4. Without JHeadstart: create a new JSF JSP page, drag and drop DeptView from the AppModule DataControl as Editable Form, drag and drop EmpView2 under DeptView to the jspx page. 5. Run the Application to verify the data is shown and the master-detail coordination works as expected.  

Add the Salary Summary to the DeptView ViewObject
We want this page to also contain the summary of all salaries in the currently selected Department. Where to put it is a later concern, let’s first get it on the page in the first place. The steps for this are: 1. Select the DeptView ViewObject and select Edit from the RMB menu 2. On the Attributes tab, press the New button to create a new (transient) attribute called SalSum. SalSum is of type Number, is Never updateable and is not mapped to Column or SQL 3. On the Java Tab, check the checkbox Generate Java File under View Row Class DeptViewRowImpl; also check the Accessors checkbox:

4. Press OK to close the VO Editor wizard.
5. From the RMB menu on the DeptView VO, select the option Goto View Row Class  
Locate the Number getSalSum() accessor method. Replace the default implementation with this one: -------------------------------------------------
public Number getSalSum() {<br /> RowIterator emps = getEmpView();<br /> Number sum = new Number(0);<br /> while (emps.hasNext()) {<br /> sum = sum.add( (Number)emps.next().getAttribute("Sal"));<br /> }<br /> return sum;<br /> }<br />  6. Add the SalarySum to the page either by dragging and dropping it from the DataControl Palette, or by synchronizing the Dept Group in the JHeadstart Application Definition editor and regenerating the application. 7. Run the application to inspect the newly added SalarySum. It should contain the correct sum of the salaries in the currently selected department. If you change the value of one of the salaries, it will currently not be updated automatically when you leave the field. It will however be synchronized for example when you sort the table by clicking one of the sortable column headers.  Creating a proper Column Footer with the Salary Summary

The next step is to create the proper layout for the Salary Summary: we want to have it displayed in Footer underneath the...
tracking img