Sun. Oct 24th, 2021

Requirement: I have Department Data displayed in the ADF Table in the User Interface. Click on the “Export Data to Excel” button, and it should download the Departments View Object Data to the Excel file.

Solution: For solution of the above requirement follow the steps as shown below:

Step 1: Create an Oracle ADF Fusion Web Application.

Create a Business Components from Tables for the Departments table of the HR Schema of the Oracle Database 11g XE Edition.

Step 2: Create a demo.jspx page. Drag and drop DepartmentVO1 from the Data Control palette on the demo.jspx page as an ADF Table.

Drag and drop af:button on the demo.jspx page.

Set text=”Export Data to Excel” and actionListener=”#{pageFlowScope.MyBean.exportDataToExcelAL}”

Thus, the complete code for the demo.jspx page is shown below:

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="" version="2.1" xmlns:f=""
    < contentType="text/html;charset=UTF-8"/>
        <af:document title="demo.jspx" id="d1">
            <af:messages id="m1"/>
            <af:form id="f1">
                <af:panelCollection id="pc1">
                    <f:facet name="menus"/>
                    <f:facet name="toolbar">
                        <af:toolbar id="t1">
                            <af:button text="Export Data to Excel" id="b1"
                    <f:facet name="statusbar"/>
                    <af:table value="#{bindings.DepartmentsVO1.collectionModel}" var="row"
                              emptyText="#{bindings.DepartmentsVO1.viewable ? 'No data to display.' : 'Access Denied.'}"
                              rowSelection="single" fetchSize="#{bindings.DepartmentsVO1.rangeSize}" id="t2">
                        <af:column headerText="#{bindings.DepartmentsVO1.hints.DepartmentId.label}" id="c1">
                            <af:outputText value="#{row.DepartmentId}"
                                           shortDesc="#{bindings.DepartmentsVO1.hints.DepartmentId.tooltip}" id="ot1">
                                <af:convertNumber groupingUsed="false"
                        <af:column headerText="#{bindings.DepartmentsVO1.hints.DepartmentName.label}" id="c2">
                            <af:outputText value="#{row.DepartmentName}"
                        <af:column headerText="#{bindings.DepartmentsVO1.hints.ManagerId.label}" id="c3">
                            <af:outputText value="#{row.ManagerId}"
                                           shortDesc="#{bindings.DepartmentsVO1.hints.ManagerId.tooltip}" id="ot3">
                                <af:convertNumber groupingUsed="false"
                        <af:column headerText="#{bindings.DepartmentsVO1.hints.LocationId.label}" id="c4">
                            <af:outputText value="#{row.LocationId}"
                                           shortDesc="#{bindings.DepartmentsVO1.hints.LocationId.tooltip}" id="ot4">
                                <af:convertNumber groupingUsed="false"

Step 3: Import the below Apache POI Jar files

Please download POI jars by clicking on this link The APACHE Software Foundation

Step 4: Write the code in the class. Thus, the complete code in the class is as shown below.



import javax.faces.event.ActionEvent;

import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCIteratorBinding;

import oracle.binding.BindingContainer;
import oracle.binding.OperationBinding;

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

import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class MyBean {

    public MyBean() {

    private static final String DOWNLOAD_FILE_PATH = "C://Users//susanto//Downloads//Departments.xlsx";

    public BindingContainer getBindingsCont() {
        return BindingContext.getCurrent().getCurrentBindingsEntry();

    public OperationBinding executeOperation(String operation) {
        OperationBinding createParam = getBindingsCont().getOperationBinding(operation);
        return createParam;

    public void exportDataToExcelAL(ActionEvent actionEvent) {
        DCIteratorBinding iter = (DCIteratorBinding) getBindingsCont().get("DepartmentsVO1Iterator");
        RowSetIterator rsi = iter.getViewObject().createRowSetIterator(null);
        XSSFWorkbook xwb = new XSSFWorkbook();
        XSSFSheet sheet = xwb.createSheet("Departments");
        int totRows = ((int) iter.getEstimatedRowCount()) + 1;
        Object[][] content = new String[totRows][4];
        int column = 4;
        content[0][0] = "Department ID";
        content[0][1] = "Department Name";
        content[0][2] = "Manager ID";
        content[0][3] = "Location ID";

        int i = 1;
        while (rsi.hasNext()) {
            Row nextRow =;
            for (int j = 0; j < column; j++) {
                if (j == 0 && nextRow.getAttribute("DepartmentId") != null) {
                    content[i][j] = nextRow.getAttribute("DepartmentId").toString();
                if (j == 1 && nextRow.getAttribute("DepartmentName") != null) {
                    content[i][j] = nextRow.getAttribute("DepartmentName").toString();
                if (j == 2 && nextRow.getAttribute("ManagerId") != null) {
                    content[i][j] = nextRow.getAttribute("ManagerId").toString();
                if (j == 3 && nextRow.getAttribute("LocationId") != null) {
                    content[i][j] = nextRow.getAttribute("LocationId").toString();
        int rowNum = 0;
        for (Object[] datatype : content) {
   row = sheet.createRow(rowNum++);
            int colNum = 0;
            for (Object field : datatype) {
                Cell cell = row.createCell(colNum++);
                if (field instanceof String) {
                    cell.setCellValue((String) field);
                } else if (field instanceof Integer) {
                    cell.setCellValue((Integer) field);
        try {
            FileOutputStream fos = new FileOutputStream(DOWNLOAD_FILE_PATH);
        } catch (FileNotFoundException e) {
        } catch (IOException e) {

Save all and run the application.

lick on the “Export Data to Excel” button, and it should download the Departments View Object Data to the Departments.xlsx file.

Hence, the solution to the error.

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

 653 total views,  1 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 *