Merge Records in Session bean by using ADF Drag/Drop

This article describes how to merge multiple selected records in Session Bean using ADF drag & drop feature.
Below described is simple use case that shows how exactly this can be achieved.

Here we will have table & user input field.Table shows  EMP records & user input field accepts Salary.When we drag & drop multiple records on user input field,the selected records get updated with the new Salary provided.


Let us suppose that we have created Java EE Web Application with Entities from Emp table.Then create EJB Session Bean & generate Data control for the same.

Write a simple code in sessionEJBBean & expose this method to local interface : 

public void updateEmprecords(List empList, Object sal)
      Emp emp = null;
      for (int i = 0; i < empList.size(); i++)
       emp = em.find(Emp.class, empList.get(i));



Now let us create updateEmpRecords.jspx page in viewController project & Drop empFindAll object as ADF Table


Define custom SelectionListener method for the table :

   public void selectionListener(SelectionEvent selectionEvent) 
    // This method gets the Empno of the selected record & stores in the list object
     UIXTable table = (UIXTable)selectionEvent.getComponent();
     FacesCtrlHierNodeBinding fcr
     Number empNo = (Number)fcr.getAttribute("empno") ;

Set table's selectedRowKeys to #{bindings.empFindAll.collectionModel.selectedRow}"

Drop inputText on the same jspx page that accepts Salary .Now we would like to drag records from the above table

& drop that on the inputtext field.This feature can be achieved by inserting dragSource operation inside the table &

dropTraget operation inside the inputText:

<af:dragSource discriminant="tab"/> //Insert this inside the table
<af:inputText label="Enter Salary" id="it13" autoSubmit="true" 
      binding="# {test.deptValue}">
      <af:dropTarget dropListener="#{test.handleTableDrop}">
       flavorClass="org.apache.myfaces.trinidad.model.RowKeySet"    discriminant="tab"/>

In the above code when the user drags & drops multiple records on inputText,the dropListener method gets called.

Goto the respective page definition file & create updateEmprecords method action& execute action



dropListener method code: 
       public DnDAction handleTableDrop(DropEvent dropEvent)
         //Below code gets the updateEmprecords method,passes parameters & executes method
           DataFlavor<RowKeySet> df = DataFlavor.getDataFlavor(RowKeySet.class);
           RowKeySet droppedKeySet = dropEvent.getTransferable().getData(df);
           if (droppedKeySet != null && droppedKeySet.size() > 0)
                 DCBindingContainer bindings =

                 OperationBinding updateEmp;
                 updateEmp= bindings.getOperationBinding("updateEmprecords");
                 updateEmp.getParamsMap().put("empList", this.getSelectedRowsList());

//Below code performs execute operation to refresh the updated records
                OperationBinding executeBinding;
                executeBinding= bindings.getOperationBinding("Execute");

                return DnDAction.NONE;

Run updateEmpRecords.jspx page & enter any Salary say '5000'.

Select multiple records in table & drop these selected records on the inputText Salary.

Note that all the selected records salary value gets updated to 5000.


Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.