Sun. Jan 17th, 2021

Requirement: I have an multipleDelete.jspx page. In that page I have a table displaying Student details from STUDENT table. In that Student table I have one more extra column named as SelectRow. This SelectRow column will have an af:selectBooleanCheckbox with the default value as false that unchecked. On top of the Student table in the ADF page I have a Delete button as shown below:

Now, when I click on the Delete button it will show the popup to delete the Selected row. Also it will have two more af:buton: Yes and Cancel as shown below:

Now, when I click on Yes it will Delete all the selected row(s) from the Student table and it will close the popup. Also it should refresh the Student table automatically.

On click of the Cancel button it will close the popup and will return to the Student table page without doing any changes.

Solution: For solution of the above requirement we will be using the Student table which is created as shown below:

create table student (student_id number(10) primary key, student_name varchar2(20),student_class varchar2(20));
insert into student values(1,'Susanto', 'MCA');
insert into student values(2,'Moumita', 'MCA');
insert into student values(3,'Vijay', 'MCA');
insert into student values(4,'Ram', 'MCA');
insert into student values(5,'Veeresh', 'BTech');
insert into student values(6,'Girish', 'BTech');
insert into student values(7,'Nilesh', 'BTech');

Thus, for solution of the above requirement follow the steps as shown below:

Step1: Create an Oracle ADF Fusion Web Application and named it as ‘DeleteMultipleRecords‘.

Step 2: Create an ADF Business Components from table for the Student table. The ADF Business Components should comprise of StudentEO, StudentVO, and ApplicationModule as shown below:

Step 3: Open StudentVO. Add a transient attribute named as SelectedRow. Set the type as Boolean and Updateable as Always as shown below:

Now, open the UI Hints tab of the StudentVO and set the Control Type as CheckBox as shown below:

Step 4: Open ViewController project and create a multipleDelete.jspx page.

Step 5: Go to Data Control. Expand AppModuleAMDataControl, Select Student1 and drag and drop in the multipleDelete.jspx page as an ADF Table

Create the binding for the af:table as binding=”#{pageFlowScope.MyBean.studentTableBind}”.

Set selected=”false” for the af:selectBooleanCheckbox.

Step 6: Drag and drop af:button from the component pallete inside the af:form and set text=”Delete”and action=”#{pageFlowScope.MyBean.deleteCheckedRows}”.

Also drag and drop af:popup from the component pallete and create binding=”#{pageFlowScope.MyBean.delConPopupBind}”.

Drag and drop af:dialog inside the af:popup and set type=”cancel”.

Drag and drop af:outputTextfrom component pallete and set value=”Are you Sure to delete?”

Drag and drop af:button inside the buttonBar facet and set text=”Yes”and actionListener=”#{pageFlowScope.MyBean.deleteConfirm}”.

Thus, the complete multipleDelete.jspx is shown below:

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <f:view>
        <af:document title="multipleDelete.jspx" id="d1">
            <af:messages id="m1"/>
            <af:form id="f1">
                <af:button text="Delete" id="b1" action="#{pageFlowScope.MyBean.deleteCheckedRows}"></af:button>
                <af:popup childCreation="deferred" autoCancel="disabled" id="p1"
                          binding="#{pageFlowScope.MyBean.delConPopupBind}">
                    <af:dialog id="d2" type="cancel">
                        <af:outputText value="Are you Sure to delete?" id="ot4"/>
                        <f:facet name="buttonBar">
                            <af:button text="Yes" id="b2" actionListener="#{pageFlowScope.MyBean.deleteConfirm}"/>
                        </f:facet>
                    </af:dialog>
                </af:popup>
                <af:table value="#{bindings.Student1.collectionModel}" var="row" rows="#{bindings.Student1.rangeSize}"
                          emptyText="#{bindings.Student1.viewable ? 'No data to display.' : 'Access Denied.'}"
                          rowBandingInterval="0" fetchSize="#{bindings.Student1.rangeSize}" id="t1"
                          binding="#{pageFlowScope.MyBean.studentTableBind}">
                    <af:column headerText="#{bindings.Student1.hints.SelectedRow.label}" id="c1">
                        <af:selectBooleanCheckbox value="#{row.bindings.SelectedRow.inputValue}"
                                                  label="#{row.bindings.SelectedRow.label}" autoSubmit="false"
                                                  shortDesc="#{bindings.Student1.hints.SelectedRow.tooltip}" id="sbc1"
                                                  selected="false">
                            <!--<af:clientAttribute name="SelectedRow" value="#{row.SelectedRow}"/>-->
                        </af:selectBooleanCheckbox>
                    </af:column>
                    <af:column headerText="#{bindings.Student1.hints.StudentId.label}" id="c2">
                        <af:outputText value="#{row.StudentId}" shortDesc="#{bindings.Student1.hints.StudentId.tooltip}"
                                       id="ot1">
                            <af:convertNumber groupingUsed="false"
                                              pattern="#{bindings.Student1.hints.StudentId.format}"/>
                        </af:outputText>
                    </af:column>
                    <af:column headerText="#{bindings.Student1.hints.StudentName.label}" id="c3">
                        <af:outputText value="#{row.StudentName}"
                                       shortDesc="#{bindings.Student1.hints.StudentName.tooltip}" id="ot2"/>
                    </af:column>
                    <af:column headerText="#{bindings.Student1.hints.StudentClass.label}" id="c4">
                        <af:outputText value="#{row.StudentClass}"
                                       shortDesc="#{bindings.Student1.hints.StudentClass.tooltip}" id="ot3"/>
                    </af:column>
                </af:table>
            </af:form>
        </af:document>
    </f:view>
</jsp:root>

Step 7: Open MyBean.java.

Create private List<Key> keyList;

Create an instance of keyList inside the MyBean(  ) constructor as keyList = new ArrayList<Key>();

Now inside the deleteCheckedRows() method we will checked which all rows have SelectedRow value as true and then store the key of all those SelectedRow in our keyList. Also we will load the popup from this method.

Inside deleteConfirm(ActionEvent actionEvent) we will iterate keyList and delete the records, commit in the database, close the popup and refresh the Student table.

Thus, the complete MyBean.java code is shown below:

package com.susanto.beans;

import java.util.ArrayList;
import java.util.List;

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.component.rich.RichPopup;
import oracle.adf.view.rich.component.rich.data.RichTable;

import oracle.adf.view.rich.component.rich.input.RichSelectBooleanCheckbox;
import oracle.adf.view.rich.context.AdfFacesContext;

import oracle.binding.BindingContainer;

import oracle.binding.OperationBinding;

import oracle.jbo.Key;
import oracle.jbo.Row;
import oracle.jbo.ViewObject;

public class MyBean {
    private RichTable studentTableBind;
    private List<Key> keyList;
    private RichPopup delConPopupBind;

    public MyBean() {
        keyList = new ArrayList<Key>();
    }

    public String deleteCheckedRows() {
        System.out.println("keyList 1: " + keyList);
        DCBindingContainer bindings = (DCBindingContainer) getBindings();
        DCIteratorBinding iter = bindings.findIteratorBinding("Student1Iterator");
        for (int i = 0; i < iter.getViewObject().getEstimatedRowCount(); i++) {
            Row row = iter.getRowAtRangeIndex(i);
            System.out.println("iter.getRowAtRangeIndex(i) : " + iter.getRowAtRangeIndex(i));
            if ((Boolean) row.getAttribute("SelectedRow") == true) {
                keyList.add(row.getKey());
            }
        }
        System.out.println("keyList 2: " + keyList);
        RichPopup.PopupHints hints = new RichPopup.PopupHints();
        getDelConPopupBind().show(hints);
        System.out.println("keyList 5: " + keyList);
        return null;
    }

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

    public void setStudentTableBind(RichTable studentTableBind) {
        this.studentTableBind = studentTableBind;
    }

    public RichTable getStudentTableBind() {
        return studentTableBind;
    }

    public void deleteConfirm(ActionEvent actionEvent) {
        System.out.println("keyList 4: " + keyList);
        if (actionEvent != null) {
            DCBindingContainer bindings = (DCBindingContainer) getBindings();
            DCIteratorBinding dci = bindings.findIteratorBinding("Student1Iterator");

            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();
            delConPopupBind.hide();
            keyList.clear();
        }
    }

    public void setDelConPopupBind(RichPopup delConPopupBind) {
        this.delConPopupBind = delConPopupBind;
    }

    public RichPopup getDelConPopupBind() {
        return delConPopupBind;
    }
}

Step 8: Save all and run the application.

Thus, the ran application is shown below:

Just for confirmation we will query the Student table in the database to see what are the records available.

Select row with StudentId1,3,6 and click on Delete button. Thus we will get the below popup.

On click of Yes button it will delete the selected rows, commit in the database, and refresh the Student table as shown below:

Just to verify whether the selected records are deleted successfully from the database we will query the Student table in the database. The result is shown below:

Thus, the selected records are deleted successfully.

Hence, the solution to our requirement.

If you like the post please comment, share, and do join me on Facebook. Please subscribe to my YouTube Channel for video tutorials.

Thanks & Regards,
Susanto Paul

 153 total views,  2 views today

By Susanto Paul

Susanto is an Oracle ACE, a qualified MCA, MBA, and a highly-skilled Senior Oracle Specialist. He is an enthusiastic Blogger and YouTuber who helps learners to solve their complex problems more efficiently. He has 9+ years of experience in multiple technologies like AWS, Oracle ADF, Oracle APEX, Oracle JET, Oracle VBCS, Oracle IDCS, Oracle PL/SQL, Oracle Integration Cloud, Java, JDBC, Servlets, JSP, Spring, Hibernate, HTML5, CSS3, JavaScript, TypeScript, NodesJS, Angular, MySQL, Oracle WebLogic Server, JUnit, JMeter, Selenium Web Driver, etc. He is a certified: Oracle Certified Professional Java SE 6 Programmer, Oracle ADF 11g Certified Implementation Specialist, Oracle Cloud Platform Application Integration 2020 Certified Specialist, Oracle Cloud Infrastructure Foundations 2020 Certified Associate, and Oracle Cloud Infrastructure Developer 2020 Certified Associate

Leave a Reply

Your email address will not be published. Required fields are marked *