JDev/ADF -- Programmatically Deleting selected rows in ADF Table

Hi,

In this post i would like to explain you, how to delete selected rows from the table programmatically.
Using check box selection.

Employees Table with select Boolean check box.


From the ValueChangeEvent, prepare one ArrayList with the keys of Selected Rows.

    public void employeeSelectionListener(ValueChangeEvent valueChangeEvent) {
        // Add event code here...
        DCIteratorBinding dci = getEmployeeIterator(); // fetches the Employee Iterator Binding
        if(valueChangeEvent != null && Boolean.parseBoolean(valueChangeEvent.getNewValue()+"")){
        Row row = dci.getCurrentRow();
        keyList.add(row.getKey());
        }
        else{
           // if the checkbox is unselected then it will remove from the list.
            Row row = dci.getCurrentRow();
            keyList.remove(row.getKey());
        }
    }



When the user clicks on the delete command button. Action event is fired then iterate through the prepared Key list and get the row based on the key, set this row as active and remove the current row from the viewObject and execute the commit operation at the end. The code is follows.

    public void deleteSelectedRowsActionListener(ActionEvent actionEvent) {
        // Add event code here...
        if(actionEvent != null){
            DCIteratorBinding dci = getEmployeeIterator();
            ViewObject vo = dci.getViewObject();
            for(int i=0; i<keyList.size(); i++){
                Row row = vo.getRow(keyList.get(i));
                vo.setCurrentRow(row);
                vo.removeCurrentRow();
            }
           OperationBinding operation = (OperationBinding)BindingContext.getCurrent().getCurrentBindingsEntry().get("Commit");
           operation.execute();
        }
    }


Download the code here  DeleteSelectedRows
This application requires connection to standard HR scheme in Oracle database.

Thanks & Regards,
Guravaiah Tata.

Comments

  1. Where have you written these two codes, I want want to write in Impl of AM and backing bean.

    ReplyDelete
    Replies
    1. Hi Surabhi,

      I have written both the methods inside backing bean. You can do implement the same logic inside AMIMPL class as well. Please tell me your requirement clearly so that i can help you out.

      Regards,
      Guru Tata

      Delete
  2. My requirement is to implement a Delete button which will delete multiple rows from ADF table as well as custom table...when I select the checkbox.

    ReplyDelete

Post a Comment

Popular posts from this blog

Common Errors - Invoking Oracle Stored procedure from MuleSoft 4.0 - DateTime formats and Default values

Apache Camel K Installation Process In a nutshell