Friday, May 11, 2012

Display multiple selected rows from ADF table in a popup window

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.

14 comments:

  1. Hi Deepak ,
    I just want to know in Application Module if we try to return a custom object (Like a POJO) then why it we are not able to expose it in service interface of Application Module or if you able to do it in different way then will you please share the code with me.
    Thank
    Nimish Gupta

    ReplyDelete
    Replies
    1. Please can you explain your scenario little more detailed, I will try from my side.

      Delete
  2. you can consider like this, think we have 4 view and i want to right a custom method in Application module java class so that i can expose those rows of data through that method instead of creating a view object. But when i am trying to use any method which return a java object then that method will not be available either in client or in service interface.
    Thanks
    Nimish Gupta

    ReplyDelete
    Replies
    1. Nimish, Sorry for late reply.

      Application module doesn't support the return value type java object, but it supports the collections. I have tried returning collection from Am and populating the data to UI components using managed bean.

      Please go through this article, it may help you - http://deepakcs.blogspot.in/2012/05/get-viewobject-attributes-pro.html

      Delete
    2. Thanks Deepak,

      But if i want to expose it as a web service can it be done in by collections.

      Thanks
      Nimish Gupta

      Delete
    3. Nimish,

      You can expose the method, where return type is of collection. In application module there is service interface tab, click on plus icon which enables support for service interface and in custom method wizard you can add your custom method.

      Regards,
      Deepak C S

      Delete
  3. Hi Deepak,
    My question is not related to your post. But I am sure you can help me. I have a master-detail table. I am implementing CRUD functionality in both the tables. It is working fine. When I insert a new row in the child table, I am auto populating tow column values, the third column value has to entered by the user. In my case, it is not happening. The third column is becoming non-editable. If I don’t auto populate those two columns, I am able to enter the value for the third column. How to achieve this? Please help me.

    ReplyDelete
    Replies
    1. Hi,
      Please can you send me your application zipped to my gmail id: deepak.siddappa@gmail.com and let me know which version of JDev is used also.

      Delete
  4. my requirment is to select row from popup and display in table which is in page from which pop up is from.How to achieve this.?

    ReplyDelete
  5. How to show multiple popup (Notifications) from ADS.

    ReplyDelete
  6. I have followed the exact same approach and able to achieve the desired result. But, in addition I have one more requirement.

    I am using applicationsTable instead of adf table. I need to have a delete operation as well on the popup along with user selected rows, which should not actually delete the row, but just hide and exclude it from the operation which is supposed to be performed by the popup. As this operation is actually performed on the base table selected rows, please provide your inputs if and how I can achieve this.

    ReplyDelete
    Replies
    1. Sent mail with updated application to you.

      Delete
  7. Hi Deepak,
    This is an excellent post. I was able to follow your post and get the desired result. I was wondering if you have any post related to Creating Tree nodes and synchronizing a read only table everytime you click on the tree node. My tree nodes go upto 5 levels deep and I want to refresh the read only table everytime I click on the node.
    Thanks a lot.

    ReplyDelete
  8. Hi Deepak,

    This is excellent, apart from this I have a requirement is, have to display selected rows in separate table below on button click. Please let me the way.
    Thanks in Advance.
    raja.adf3@gmail.com

    ReplyDelete