Search This Blog

Delete Selected Rows from Table with Select all option Boolean check box - ADF with POP up

Delete  Selected Rows from Table with Select all option Boolean check box



This is the Java code in the Bean:
package demo.view;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;

import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCBindingContainer;
import oracle.adf.model.binding.DCIteratorBinding;
import oracle.adf.view.rich.event.DialogEvent;
import oracle.adf.view.rich.event.PopupCanceledEvent;
import oracle.adf.view.rich.event.PopupFetchEvent;

import oracle.binding.OperationBinding;

import oracle.jbo.Row;
import oracle.jbo.RowSetIterator;


public class employeeOperations {
    public employeeOperations() {
    }

    public void deleteMultiple(ActionEvent actionEvent) {
        DCBindingContainer bindings = getBindings();
        DCIteratorBinding iteratorBinding = bindings.findIteratorBinding("EmployeeVO1Iterator");

        Row[] r = iteratorBinding.getViewObject().getFilteredRows("SelectBox", true);
        for (int i = 0; i < r.length; i++) {
            r[i].remove();
        }

        OperationBinding operationBinding = bindings.getOperationBinding("Commit");
        operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty()) {
            addFacesMessage(FacesMessage.SEVERITY_ERROR, "Error in Deleting Records");

        } else {
            addFacesMessage(FacesMessage.SEVERITY_INFO, "Records Deleted Succesfully");
        }
    }

    public void dialogListener(DialogEvent dialogEvent) {
        if (dialogEvent.getOutcome().name().equals("ok")) {
            DCBindingContainer bindings = getBindings();
            OperationBinding method = bindings.getOperationBinding("Commit");
            method.execute();
        } else if (dialogEvent.getOutcome().name().equals("cancel")) {
            DCBindingContainer bindings = getBindings();
            OperationBinding method = bindings.getOperationBinding("Rollback");
            method.execute();
        }
        System.out.println("dialogListener Executed");
    }

    public static void addFacesMessage(FacesMessage.Severity severity, String message) {
        FacesMessage fm = new FacesMessage(severity, message, null);
        FacesContext.getCurrentInstance().addMessage(null, fm);
    }

    public DCBindingContainer getBindings() {
        return (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
    }

    public void popupCancelListener(PopupCanceledEvent popupCanceledEvent) {
        DCBindingContainer bindings = getBindings();
        OperationBinding method = bindings.getOperationBinding("Rollback");
        method.execute();
        System.out.println("popupCancelListener Executed");
    }

    public void popupFetchListener(PopupFetchEvent popupFetchEvent) {
        DCBindingContainer bindings = getBindings();
        OperationBinding method = bindings.getOperationBinding("CreateInsert");
        method.execute();
        System.out.println("popupFetchListener Executed");
    }

    public void selectAllRows(ValueChangeEvent valueChangeEvent) {
        DCBindingContainer bindings = getBindings();
        DCIteratorBinding it = bindings.findIteratorBinding("EmployeeVO1Iterator");
        RowSetIterator rit = it.getRowSetIterator();
        //rit.reset();
        if (valueChangeEvent.getNewValue() != null) {
            Boolean selectAll = Boolean.parseBoolean(valueChangeEvent.getNewValue().toString());
            if (rit.first() != null) {
                Row r = rit.first();
                r.setAttribute("SelectBox", selectAll);
            }
            while (rit.hasNext()) {
                Row r = rit.next();
                if (r != null) {
                    r.setAttribute("SelectBox", selectAll);
                }
            }
        }
    }
}
This is the code in the Main.jspx for the checkBox created on the header:
<f:facet name="header">
    <af:selectbooleancheckbox autosubmit="true" id="sbc2" simple="true" valuechangelistener="#{HRBean.selectAllRows}">
</af:selectbooleancheckbox></f:facet>

1 comment:

  1. Thanks for sharing this great information I am impressed by the information that you have on this blog. Same as your blog i found another one Oracle ADF .
    Actually, I was looking for the same information on internet for
    Oracle ADF Interview Questions and Answers/Tips and came across your blog. I am impressed by the information that you have on this blog. It shows how well you understand this subject.

    ReplyDelete