In this post I'm sharing sample for how to display multiple selected rows from ADF table in a popup window.
Solution
Create a new extended view from the parent view. In Application Module create a view criteria with IN clause at run time and execute the view, this is one of the approach to display the contents of all the selected rows in a popup window.
You can
download the sample workspace from here
[Runs with Oracle JDeveloper 11.1.2.0.0 (11g R2) + HR Schema]
Implementation Steps
Create Fusion Web Application with business components from tables based on Departments table. Now create a new extended object from DepartmentsView as shown in below image.
Open the AppModule and select Data Model tab move "childDepartmentsView" from available view objects to data model.
Next go to Java tab in AppModule and click on edit java options. Generate the application module class: AppModuleImpl.java.
Open the AppModuleImpl.java file and the below method code.
/**
* This method create's the view crietria at the runtime,
* set the IN clause operator by accessing the ChildDepartmentsView1
* @param deptList
*/
public void populateSelectedRows(List deptList) {
try {
ViewObject childDeptVo = getChildDepartmentsView1();
ViewCriteria childDeptVC = childDeptVo.createViewCriteria();
ViewCriteriaRow childDeptVCRow = childDeptVC.createViewCriteriaRow();
ViewCriteriaItem childDeptVCRowItem = childDeptVCRow.ensureCriteriaItem("DepartmentId");
childDeptVCRowItem.setOperator("IN");
for (int i = 0; i < deptList.size(); i++) {
childDeptVCRowItem.setValue(i, deptList.get(i));
}
childDeptVC.addElement(childDeptVCRow);
childDeptVo.applyViewCriteria(childDeptVC);
childDeptVo.executeQuery();
} catch (Exception e) {
e.printStackTrace();
}
}
Go back to AppModuleImpl.java and select Java tab in client interface section move populateSelectedRows from available to selected block.
In ViewController project, create index.jspx page and drag and drop DepartmentsView1->Table as ADF Read-only Table with rowSlection as multiple and create the backingBean as "IndexBean". Surround the table with panel collection, add the toolbar, drop button inside toolbar and name as "Edit".
From component palette drag and drop ADF popup, ContinentDelivery as lazyUncached. Drop dialog inside the popup, Type as none. Now drag and drop ChildDepartmentsView1->Table as ADF Table.
Open the index.jspx page, bind the departments table to the backing bean as show below.
Create the ActionListener method called "editAction" for Edit button.
Open the IndexBean backing bean and add the below method code.
private List selectedRowKeys;
public void editAction(ActionEvent actionEvent) {
getSelectedRowKeys();
BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
OperationBinding oper = bindings.getOperationBinding("populateSelectedRows");
oper.execute();
ExtendedRenderKitService erkService =
Service.getService(FacesContext.getCurrentInstance().getRenderKit(), ExtendedRenderKitService.class);
erkService.addScript(FacesContext.getCurrentInstance(),
"var hints = {autodismissNever:true}; " + "AdfPage.PAGE.findComponent('p1').show(hints);");
}
public List getSelectedRowKeys() {
selectedRowKeys = null;
RowKeySet selectedDepts = getDeptTable().getSelectedRowKeys();
Iterator selectedDeptIter = selectedDepts.iterator();
DCBindingContainer bindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding deptIter = bindings.findIteratorBinding("DepartmentsView1Iterator");
RowSetIterator deptRSIter = deptIter.getRowSetIterator();
selectedRowKeys = new ArrayList();
while (selectedDeptIter.hasNext()) {
Key key = (Key)((List)selectedDeptIter.next()).get(0);
Row currentRow = deptRSIter.getRow(key);
selectedRowKeys.add(currentRow.getAttribute("DepartmentId"));
}
return selectedRowKeys;
}
Go to Bindings tab in index.jspx page, add populateSelectedRows method action and map the parameter to backingBeanScope variable.
Run the index.jspx page, select the multiple rows and click on edit button. Popup window should contains all the selected rows as shown below.