Wednesday, March 29, 2023

af:fileDownloadActionListener excel custom code

-- page--  

   <af:button id="b7" icon="/images/excel.png" shortDesc="Export">

                        <af:fileDownloadActionListener contentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

                                                       filename="PickHaulProposals.xls"

                                                       method="#{WorkbenchBean.generateExcel}"/>

                    </af:button>


---bean------

public void generateExcel(FacesContext facesContext, OutputStream outputStream)

    {

        try

        {


            HSSFWorkbook workbook = new HSSFWorkbook();

            HSSFSheet worksheet = workbook.createSheet("PickHaulProposals");


            DCBindingContainer bindings = (DCBindingContainer) BindingContext.getCurrent().getCurrentBindingsEntry();

            DCIteratorBinding dcIteratorBindings = bindings.findIteratorBinding("TWCPickHaulInvWorkbenchVO1Iterator");

            HSSFRow excelrow = null;

            RowSetIterator rsi = dcIteratorBindings.getViewObject().createRowSetIterator(null);


            int i = 0;

            excelrow = (HSSFRow) worksheet.createRow((short) i);

            short j = 0;


            HSSFCellStyle decimalStyle = workbook.createCellStyle();

            HSSFDataFormat hssfDataFormat = workbook.createDataFormat(); 

            decimalStyle.setDataFormat(hssfDataFormat.getFormat("#,##0.00000"));

            

            DecimalFormat df = new DecimalFormat("#.00000");

            

            HSSFCellStyle style = workbook.createCellStyle();

            style.setFillBackgroundColor(HSSFColor.BLUE_GREY.index);

            style.setFillForegroundColor(HSSFColor.WHITE.index);

            style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);


            HSSFFont font = workbook.createFont();

            font.setFontName(HSSFFont.FONT_ARIAL);

            font.setColor((short) HSSFColor.BLACK.index);

            font.setFontHeightInPoints((short) 10);

            font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

            style.setFont(font);


            HSSFCell cellA1 = excelrow.createCell(0);

            cellA1.setCellValue("Select Flag");


            cellA1 = excelrow.createCell(1);

            cellA1.setCellValue("Invoice Type");


            cellA1 = excelrow.createCell(2);

            cellA1.setCellValue("Harvest Ticket Number");


            cellA1 = excelrow.createCell(3);

            cellA1.setCellValue("Invoice Number");


            cellA1 = excelrow.createCell(4);

            cellA1.setCellValue("Harvest Year");


            cellA1 = excelrow.createCell(5);

            cellA1.setCellValue("Region");


            cellA1 = excelrow.createCell(6);

            cellA1.setCellValue("Variety");


            cellA1 = excelrow.createCell(7);

            cellA1.setCellValue("Pool Number");


            cellA1 = excelrow.createCell(8);

            cellA1.setCellValue("Picked Date");


            cellA1 = excelrow.createCell(9);

            cellA1.setCellValue("Received date");


            cellA1 = excelrow.createCell(10);

            cellA1.setCellValue("Ranch Block");


            cellA1 = excelrow.createCell(11);

            cellA1.setCellValue("Ranch");


            cellA1 = excelrow.createCell(12);

            cellA1.setCellValue("Vendor");


            cellA1 = excelrow.createCell(13);

            cellA1.setCellValue("Vendor Site Code");


            cellA1 = excelrow.createCell(14);

            cellA1.setCellValue("UOM");


            cellA1 = excelrow.createCell(15);

            cellA1.setCellValue("Quantity Received");


            cellA1 = excelrow.createCell(16);

            cellA1.setCellValue("Rate");


            cellA1 = excelrow.createCell(17);

            cellA1.setCellValue("Amount Owed");


            cellA1 = excelrow.createCell(18);

            cellA1.setCellValue("Subsidy");


            cellA1 = excelrow.createCell(19);

            cellA1.setCellValue("Status");

            

            cellA1 = excelrow.createCell(20);

            cellA1.setCellValue("Accrual Status");


            cellA1 = excelrow.createCell(21);

            cellA1.setCellValue("Creation Date");


            cellA1 = excelrow.createCell(22);

            cellA1.setCellValue("Submitted Date");


            cellA1 = excelrow.createCell(23);

            cellA1.setCellValue("Paid Date");


            cellA1 = excelrow.createCell(24);

            cellA1.setCellValue("Last Updated By");

            


            

            for (int k = 0; k <= 24; k++)

            {

                excelrow.getCell(k).setCellStyle(style);

            }

            Row worknechRows[]=rsi.getAllRowsInRange();

            while(worknechRows!=null && worknechRows.length >0){

            for(Row row : worknechRows)

            //while (rsi.hasNext())

            {


                //Row row = rsi.next();


                //print data from second row in excel

                ++i;

                int colIndex = 0;

                excelrow = worksheet.createRow((int) i);

                for (String colName: row.getAttributeNames())

                {

                    log.info("Columns Name " + colName);

                    log.info("Column data " + row.getAttribute(colName));


                    if (colName.equalsIgnoreCase("SelectCheck"))

                    {

                        HSSFCell cell = excelrow.createCell(0);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }



                    } else if (colName.equalsIgnoreCase("InvType"))

                    {

                        HSSFCell cell = excelrow.createCell(1);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }



                    } else if (colName.equalsIgnoreCase("HarvestTicketNum"))

                    {

                        HSSFCell cell = excelrow.createCell(2);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("InvNumber"))

                    {

                        HSSFCell cell = excelrow.createCell(3);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("HarvestYear"))

                    {

                        HSSFCell cell = excelrow.createCell(4);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("HarvestRegion"))

                    {

                        HSSFCell cell = excelrow.createCell(5);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("Variety"))

                    {

                        HSSFCell cell = excelrow.createCell(6);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("PoolNumber"))

                    {

                        HSSFCell cell = excelrow.createCell(7);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("PickedDate"))

                    {

                        HSSFCell cell = excelrow.createCell(8);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("ReceivedDate"))

                    {

                        HSSFCell cell = excelrow.createCell(9);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("RanchBlockNumber"))

                    {

                        HSSFCell cell = excelrow.createCell(10);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("RanchBlockName"))

                    {

                        HSSFCell cell = excelrow.createCell(11);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("VendorName"))

                    {

                        HSSFCell cell = excelrow.createCell(12);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("VendorSiteCode"))

                    {

                        HSSFCell cell = excelrow.createCell(13);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("Uom"))

                    {

                        HSSFCell cell = excelrow.createCell(14);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("QtyReceived"))

                    {

                        HSSFCell cell = excelrow.createCell(15);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(Float.parseFloat(row.getAttribute(colName).toString()));

                            cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("Rate"))

                    {

                        HSSFCell cell = excelrow.createCell(16);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(Double.valueOf(df.format(Float.parseFloat(row.getAttribute(colName).toString()))));

                            cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);

                            //cell.setCellStyle(decimalStyle);

                            

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("AmtOwed"))

                    {

                        HSSFCell cell = excelrow.createCell(17);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(Double.valueOf(df.format(Float.parseFloat(row.getAttribute(colName).toString()))));

                            cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);

                            //cell.setCellStyle(decimalStyle);

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("Subsidy"))

                    {

                        HSSFCell cell = excelrow.createCell(18);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(Float.parseFloat(row.getAttribute(colName).toString()));

                            cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("Status"))

                    {

                        HSSFCell cell = excelrow.createCell(19);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    }else if (colName.equalsIgnoreCase("Accrual"))

                    {

                        HSSFCell cell = excelrow.createCell(20);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    }else if (colName.equalsIgnoreCase("CreationDate")) {

                        final HSSFCell cell = excelrow.createCell(21);

                        if (null != row.getAttribute(colName)) {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        }

                        else {

                            cell.setCellValue("");

                        }

                    }

                    else if (colName.equalsIgnoreCase("SubmittedDate")) {

                        final HSSFCell cell = excelrow.createCell(22);

                        if (null != row.getAttribute(colName)) {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        }

                        else {

                            cell.setCellValue("");

                        }

                    }

                    else if (colName.equalsIgnoreCase("PaidDate")) {

                        final HSSFCell cell = excelrow.createCell(23);

                        if (null != row.getAttribute(colName)) {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        }

                        else {

                            cell.setCellValue("");

                        }

                    }

                    else if (colName.equalsIgnoreCase("LastUpdatedBy")) {

                        final HSSFCell cell = excelrow.createCell(24);

                        if (null != row.getAttribute(colName)) {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        }

                        else {

                            cell.setCellValue("");

                        }

                    }

                }


                worksheet.createFreezePane(0, 1, 0, 1);

                

            }

            worknechRows=rsi.getNextRangeSet(); 

                

            }

            rsi.closeRowSetIterator();

            workbook.write(outputStream);

            outputStream.flush();


        } catch (Exception e)

        {

            e.printStackTrace();

        }

    }


--------------------------------------------

    public void generateExcel(FacesContext facesContext, OutputStream outputStream)

    {

        try

        {

            SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");  

                Date date = new Date();  

                System.out.println("@@Starting:@@"+formatter.format(date)); 

            HSSFWorkbook workbook = new HSSFWorkbook();

            HSSFSheet worksheet = workbook.createSheet("PickHaulProposals");


            DCBindingContainer bindings = (DCBindingContainer) BindingContext.getCurrent().getCurrentBindingsEntry();

            DCIteratorBinding dcIteratorBindings = bindings.findIteratorBinding("TWCPickHaulInvWorkbenchVO1Iterator");

            HSSFRow excelrow = null;

            RowSetIterator rsi = dcIteratorBindings.getViewObject().createRowSetIterator(null);


            int i = 0;

            excelrow = (HSSFRow) worksheet.createRow((short) i);

            short j = 0;


            HSSFCellStyle decimalStyle = workbook.createCellStyle();

            HSSFDataFormat hssfDataFormat = workbook.createDataFormat(); 

            decimalStyle.setDataFormat(hssfDataFormat.getFormat("#,##0.00000"));

            

            DecimalFormat df = new DecimalFormat("#.00000");

            

            HSSFCellStyle style = workbook.createCellStyle();

            style.setFillBackgroundColor(HSSFColor.BLUE_GREY.index);

            style.setFillForegroundColor(HSSFColor.WHITE.index);

            style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);


            HSSFFont font = workbook.createFont();

            font.setFontName(HSSFFont.FONT_ARIAL);

            font.setColor((short) HSSFColor.BLACK.index);

            font.setFontHeightInPoints((short) 10);

            font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

            style.setFont(font);


            HSSFCell cellA1 = excelrow.createCell(0);

            cellA1.setCellValue("Select Flag");


            cellA1 = excelrow.createCell(1);

            cellA1.setCellValue("Invoice Type");


            cellA1 = excelrow.createCell(2);

            cellA1.setCellValue("Harvest Ticket Number");


            cellA1 = excelrow.createCell(3);

            cellA1.setCellValue("Invoice Number");


            cellA1 = excelrow.createCell(4);

            cellA1.setCellValue("Harvest Year");


            cellA1 = excelrow.createCell(5);

            cellA1.setCellValue("Region");


            cellA1 = excelrow.createCell(6);

            cellA1.setCellValue("Variety");


            cellA1 = excelrow.createCell(7);

            cellA1.setCellValue("Pool Number");


            cellA1 = excelrow.createCell(8);

            cellA1.setCellValue("Picked Date");


            cellA1 = excelrow.createCell(9);

            cellA1.setCellValue("Received date");


            cellA1 = excelrow.createCell(10);

            cellA1.setCellValue("Ranch Block");


            cellA1 = excelrow.createCell(11);

            cellA1.setCellValue("Ranch");


            cellA1 = excelrow.createCell(12);

            cellA1.setCellValue("Vendor");


            cellA1 = excelrow.createCell(13);

            cellA1.setCellValue("Vendor Site Code");


            cellA1 = excelrow.createCell(14);

            cellA1.setCellValue("UOM");


            cellA1 = excelrow.createCell(15);

            cellA1.setCellValue("Quantity Received");


            cellA1 = excelrow.createCell(16);

            cellA1.setCellValue("Rate");


            cellA1 = excelrow.createCell(17);

            cellA1.setCellValue("Amount Owed");


            cellA1 = excelrow.createCell(18);

            cellA1.setCellValue("Subsidy");


            cellA1 = excelrow.createCell(19);

            cellA1.setCellValue("Status");

            

            cellA1 = excelrow.createCell(20);

            cellA1.setCellValue("Accrual Status");


            cellA1 = excelrow.createCell(21);

            cellA1.setCellValue("Creation Date");


            cellA1 = excelrow.createCell(22);

            cellA1.setCellValue("Submitted Date");


            cellA1 = excelrow.createCell(23);

            cellA1.setCellValue("Paid Date");


            cellA1 = excelrow.createCell(24);

            cellA1.setCellValue("Last Updated By");

            


            

            for (int k = 0; k <= 24; k++)

            {

                excelrow.getCell(k).setCellStyle(style);

            }

            Row worknechRows[]=rsi.getAllRowsInRange();

            while(worknechRows!=null && worknechRows.length >0){

            for(Row row : worknechRows)

            //while (rsi.hasNext())

            {


                //Row row = rsi.next();


                //print data from second row in excel

                ++i;

                int colIndex = 0;

                excelrow = worksheet.createRow((int) i);

                for (String colName: row.getAttributeNames())

                {

                    log.info("Columns Name " + colName);

                    log.info("Column data " + row.getAttribute(colName));


                    if (colName.equalsIgnoreCase("SelectCheck"))

                    {

                        HSSFCell cell = excelrow.createCell(0);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }



                    } else if (colName.equalsIgnoreCase("InvType"))

                    {

                        HSSFCell cell = excelrow.createCell(1);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }



                    } else if (colName.equalsIgnoreCase("HarvestTicketNum"))

                    {

                        HSSFCell cell = excelrow.createCell(2);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("InvNumber"))

                    {

                        HSSFCell cell = excelrow.createCell(3);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("HarvestYear"))

                    {

                        HSSFCell cell = excelrow.createCell(4);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("HarvestRegion"))

                    {

                        HSSFCell cell = excelrow.createCell(5);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("Variety"))

                    {

                        HSSFCell cell = excelrow.createCell(6);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("PoolNumber"))

                    {

                        HSSFCell cell = excelrow.createCell(7);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("PickedDate"))

                    {

                        HSSFCell cell = excelrow.createCell(8);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("ReceivedDate"))

                    {

                        HSSFCell cell = excelrow.createCell(9);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("RanchBlockNumber"))

                    {

                        HSSFCell cell = excelrow.createCell(10);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("RanchBlockName"))

                    {

                        HSSFCell cell = excelrow.createCell(11);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("VendorName"))

                    {

                        HSSFCell cell = excelrow.createCell(12);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("VendorSiteCode"))

                    {

                        HSSFCell cell = excelrow.createCell(13);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("Uom"))

                    {

                        HSSFCell cell = excelrow.createCell(14);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("QtyReceived"))

                    {

                        HSSFCell cell = excelrow.createCell(15);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(Float.parseFloat(row.getAttribute(colName).toString()));

                            cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("Rate"))

                    {

                        HSSFCell cell = excelrow.createCell(16);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(Double.valueOf(df.format(Float.parseFloat(row.getAttribute(colName).toString()))));

                            cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);

                            //cell.setCellStyle(decimalStyle);

                            

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("AmtOwed"))

                    {

                        HSSFCell cell = excelrow.createCell(17);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(Double.valueOf(df.format(Float.parseFloat(row.getAttribute(colName).toString()))));

                            cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);

                            //cell.setCellStyle(decimalStyle);

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("Subsidy"))

                    {

                        HSSFCell cell = excelrow.createCell(18);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(Float.parseFloat(row.getAttribute(colName).toString()));

                            cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);

                        } else

                        {

                            cell.setCellValue("");

                        }


                    } else if (colName.equalsIgnoreCase("Status"))

                    {

                        HSSFCell cell = excelrow.createCell(19);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    }else if (colName.equalsIgnoreCase("Accrual"))

                    {

                        HSSFCell cell = excelrow.createCell(20);

                        if (null != row.getAttribute(colName))

                        {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        } else

                        {

                            cell.setCellValue("");

                        }


                    }else if (colName.equalsIgnoreCase("CreationDate")) {

                        final HSSFCell cell = excelrow.createCell(21);

                        if (null != row.getAttribute(colName)) {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        }

                        else {

                            cell.setCellValue("");

                        }

                    }

                    else if (colName.equalsIgnoreCase("SubmittedDate")) {

                        final HSSFCell cell = excelrow.createCell(22);

                        if (null != row.getAttribute(colName)) {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        }

                        else {

                            cell.setCellValue("");

                        }

                    }

                    else if (colName.equalsIgnoreCase("PaidDate")) {

                        final HSSFCell cell = excelrow.createCell(23);

                        if (null != row.getAttribute(colName)) {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        }

                        else {

                            cell.setCellValue("");

                        }

                    }

                    else if (colName.equalsIgnoreCase("LastUpdatedBy")) {

                        final HSSFCell cell = excelrow.createCell(24);

                        if (null != row.getAttribute(colName)) {

                            cell.setCellValue(row.getAttribute(colName).toString());

                        }

                        else {

                            cell.setCellValue("");

                        }

                    }

                }


                worksheet.createFreezePane(0, 1, 0, 1);

                

            }

            worknechRows=rsi.getNextRangeSet(); 

                

            }

            rsi.closeRowSetIterator();

            workbook.write(outputStream);

            outputStream.flush();

           // SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");  

                Date date1 = new Date();  

                System.out.println("@@Ending:@@"+formatter.format(date1)); 

        } catch (Exception e)

        {

            e.printStackTrace();

        }

    }

Friday, March 24, 2023

ADF logger

 https://www.lkakarla.com/2012/09/logging-data-in-adf-using-adf-logger.html

Tuesday, February 7, 2023

Vo do not query while page loading code for voImpl

     int counter =0;

    /**

     * executeQueryForCollection - overridden for custom java data source support.

     */

    protected void executeQueryForCollection(Object qc, Object[] params, int noUserParams) {

     if (counter > 0) {

            super.executeQueryForCollection(qc, params, noUserParams);

        } else {

            counter = counter + 1;

        }

    }  

Friday, February 3, 2023

header grid to detail grid row value setting from AMImpl class while search the data

     //Added by Naren

    public HashMap searchAppointmentExecute() {

        //   ArrayList<String> orderStatusVal = new ArrayList<String>();//Added by Bush Adimulapu :: 11-Aug-2022

        HashMap<String, String> orderStatusValMap =

            new HashMap<String, String>(); //Added by Madhavi Bolloju :: 11-Oct-2022

        HashMap shipOrderMap = null;

        TWCYMTAppointmentDashboardSearchVOImpl appointmentSearchVO = this.getTWCYMTAppointmentDashboardSearchVO1();

        TWCYMTAppointmentDashboardSearchVORowImpl appointmentSearchRow =

            (TWCYMTAppointmentDashboardSearchVORowImpl) appointmentSearchVO.getCurrentRow();


        _logger.info("Organization_code: " + appointmentSearchRow.getOrganizationCode() + " appointment_date: " +

                     appointmentSearchRow.getAppointmentDate() + " service_type: " +

                     appointmentSearchRow.getServiceType() + " Appointment Number: " +

                     appointmentSearchRow.getAppointmentNum() + " Sales order number: " +

                     appointmentSearchRow.getSalesOrdNum() + " AppointmentTodate: " +

                     appointmentSearchRow.getAppointmentTodate());

        ADFContext adfCtx = null;

        adfCtx = ADFContext.getCurrent();

        long noOfDays = (Long)adfCtx.getPageFlowScope().get("NOOFDAYS");

        System.out.println("AM noOfDays@@"+noOfDays);   

        if(noOfDays==0L){

        TWCYMTAppointmentDashboardVOImpl appointmentVO = this.getTWCYMTAppointmentDashboardVO1(); //Pivot query


        appointmentVO.setNamedWhereClauseParam("pfacility", appointmentSearchRow.getOrganizationCode());

        appointmentVO.setNamedWhereClauseParam("pplannedstartdate", appointmentSearchRow.getAppointmentDate());


        _logger.info("appointmentVO getQuery " + appointmentVO.getQuery());

        appointmentVO.executeQuery();

        // _logger.info("appointmentVO estimatedRowCount "+appointmentVO.getEstimatedRowCount());

    

        //HashMap shipOrderMap = null;

        shipOrderMap = new HashMap();


        RowSet rs = appointmentVO.getRowSet();

        RowSetIterator rowIter = rs.createRowSetIterator(null);


        while (rowIter.hasNext()) {

            Row row = rowIter.next();

            shipOrderMap.put(row.getAttribute("Orders"), row.getAttribute("ShipCode"));

            //_logger.info("map values " + row.getAttribute("Orders") + " - " + row.getAttribute("ShipCode"));

        }

        }

        //rowIter.closeRowSetIterator();

        //rs.closeRowSet();

        _logger.info("AMImpl shipOrderMap " + shipOrderMap);

        /* TWCYMTDraftAppointmentsVOImpl draftAppointmentVO = this.getTWCYMTDraftAppointmentsVO1();

        draftAppointmentVO.setNamedWhereClauseParam("pfacility",appointmentSearchRow.getOrganizationCode());

        draftAppointmentVO.setNamedWhereClauseParam("pplannedstartdate", appointmentSearchRow.getAppointmentDate());

        draftAppointmentVO.setNamedWhereClauseParam("pservicetype", appointmentSearchRow.getServiceType());

        //#828-TMS Enhancements-48- Added by Manasa Yalamarthy on 18th Dec,2020

        draftAppointmentVO.setNamedWhereClauseParam("psales_order_number", appointmentSearchRow.getSalesOrdNum());

        draftAppointmentVO.setNamedWhereClauseParam("pappointmentnum", appointmentSearchRow.getAppointmentNum());

        draftAppointmentVO.setNamedWhereClauseParam("pwmsordernumber", appointmentSearchRow.getWmsOrderNum());  // Added by Jayanand for TMS 1A Issues 02-06-2021

        draftAppointmentVO.setNamedWhereClauseParam("pShipmentNo", appointmentSearchRow.getShipmentNum());  // Added by Muzammil :: OTM TMS changes

        _logger.info("draftAppointmentVO getQuery "+ draftAppointmentVO.getQuery());

        draftAppointmentVO.executeQuery();

        _logger.info("draftAppointmentVO estimatedRowCount "+draftAppointmentVO.getEstimatedRowCount()); */


        TWCYMTAppointmentVOImpl appointmentHdrVO = this.getTWCYMTAppointmentVO1();

        ViewCriteria vc = appointmentHdrVO.getViewCriteria("TWCYMTAppointmentVOCriteria");

        appointmentHdrVO.applyViewCriteria(vc);

        appointmentHdrVO.setNamedWhereClauseParam("pAppointmentNumber", appointmentSearchRow.getAppointmentNum());

        appointmentHdrVO.setNamedWhereClauseParam("pFacility", appointmentSearchRow.getOrganizationCode());

        appointmentHdrVO.setNamedWhereClauseParam("pDock", "");

        appointmentHdrVO.setNamedWhereClauseParam("pFromDate", appointmentSearchRow.getAppointmentDate());

        appointmentHdrVO.setNamedWhereClauseParam("pToDate",  appointmentSearchRow.getAppointmentTodate());

        appointmentHdrVO.setNamedWhereClauseParam("pStatus", appointmentSearchRow.getStatus());

        appointmentHdrVO.setNamedWhereClauseParam("pServiceType", appointmentSearchRow.getServiceType());

        appointmentHdrVO.setNamedWhereClauseParam("pLoadNumber", appointmentSearchRow.getShipmentNum());

        appointmentHdrVO.setNamedWhereClauseParam("pSalesOrderNbr", appointmentSearchRow.getSalesOrdNum());

        appointmentHdrVO.setNamedWhereClauseParam("pWmsorderNum", appointmentSearchRow.getWmsOrderNum());

        _logger.info("appointmentHdrVO getQuery " + appointmentHdrVO.getQuery());

        appointmentHdrVO.executeQuery();


        //Get Order Status with API :: Added by Bush Adimulapu

        this.getWMSEnvDetails();

        // RowSetIterator draftRowIter = draftAppointmentVO.createRowSetIterator(null);

        RowSetIterator draftRowIter = appointmentHdrVO.createRowSetIterator(null);

        ArrayList<String> salesOrderNumArray = new ArrayList<String>();

        while (draftRowIter.hasNext()) {

            Row row = draftRowIter.next();

            String salesOrderNum = (String) row.getAttribute("SalesOrderNbr");

            _logger.info("SalesOrderNbr " + salesOrderNum);


            if (!salesOrderNumArray.contains(salesOrderNum)) {

                salesOrderNumArray.add((String) row.getAttribute("SalesOrderNbr"));

            }

        }

        //Below logic added by Janardhan on Oct 18,2022

        String orderList = salesOrderNumArray.toString();

        orderList = orderList.replace("[", "")

                             .replace("]", "")

                             .replace(" ", "");

        _logger.info("order list is " + orderList);

        //Get order Status With single API call:: Added By Madhavi Bolloju

        orderStatusValMap = this.getAppointmentStatus(orderList);


        _logger.info("orderStatusVal.size(): " + orderStatusValMap.size());


        draftRowIter.reset();

        while (draftRowIter.hasNext()) {

            //Row row = draftRowIter.next();

            TWCYMTAppointmentVORowImpl row = (TWCYMTAppointmentVORowImpl)draftRowIter.next();

            String salesOrderNum = (String) row.getAttribute("SalesOrderNbr");

            _logger.info("SalesOrderNbr " + salesOrderNum);

            //String statusId = orderStatusValMap.get(salesOrderNum);

            //Added by Janardhan Chilukuri :: 06 Jan 2023 for Order Status

            String statusId = "";

            String status = "";

            if (salesOrderNum!=null && salesOrderNum.contains(",") && !orderStatusValMap.isEmpty()) {

                String[] salesOrders = salesOrderNum.split(",");

                for (String order : salesOrders) {

                _logger.info("Sales Order Number is " + order);

                System.out.println("Sales Order Number is " + order);

                status = orderStatusValMap.get(order);

                System.out.println("status is " + status);

                RowIterator ordIter = row.getTWCYMTAppointmentOrdersVO();

                while(ordIter.hasNext()){

                Row row1 = (Row) ordIter.next();

                System.out.println(order+":order @@SalesOrderNumber@@"+row1.getAttribute("SalesOrderNumber").toString());

                if(row1.getAttribute("SalesOrderNumber").toString().equalsIgnoreCase(order)){

                status = status == null ? "0" : status;

                if (status != null) {

                    if (status.equalsIgnoreCase("0")) {

                        row1.setAttribute("Description", "Created"); //SalesOrderStatus

                    } else if (status.equalsIgnoreCase("90")) {

                        row1.setAttribute("Description", "Shipped");

                    } else {

                        row1.setAttribute("Description", "In Progress");

                    }

                }    

                //row1.setAttribute("Description", status);

                }

               }

            }

            } else {

                statusId = orderStatusValMap.get(salesOrderNum);

            }

            statusId = statusId == null ? "0" : statusId;

            if (statusId != null) {

                if (statusId.equalsIgnoreCase("0")) {

                    row.setAttribute("SalesOrderStatus", "Created"); //SalesOrderStatus

                } else if (statusId.equalsIgnoreCase("90")) {

                    row.setAttribute("SalesOrderStatus", "Shipped");

                } else {

                    row.setAttribute("SalesOrderStatus", "In Progress");

                }

            }


        }


        draftRowIter.closeRowSetIterator();

        return shipOrderMap;

    }

Sunday, January 29, 2023

button action calling in another method

             ActionEvent ae = new ActionEvent(getCb1());

            ae.queue();

Tuesday, January 24, 2023

rollback clearing the row values

         public String closeOrdActionRevertOrremoveRowValues() {

        DCBindingContainer dcBindings = (DCBindingContainer) BindingContext.getCurrent().getCurrentBindingsEntry();

        DCIteratorBinding appointOrdersIter = dcBindings.findIteratorBinding("TWCYMTAppointmentOrdersVO1Iterator");


        ViewObject appointOrdersVO = appointOrdersIter.getViewObject();

        RowSetIterator OrdersIter = appointOrdersVO.createRowSetIterator(null);

        while (OrdersIter.hasNext()) {

            Row nextRow = OrdersIter.next();

            if (nextRow.getAttribute("CheckRowStatusT") != null) {

                Integer rowStatus = (Integer) nextRow.getAttribute("CheckRowStatusT");

                if (rowStatus == 2) {

                    _logger.info("Modified Rows-" + nextRow.getAttribute("AppointmentNumber"));

                    revertChangesCurrentRow(nextRow);

                } else if (rowStatus == 0) {

                    _logger.info("New Row Removed");

                    nextRow.remove();

                }

            }

        }

        appointOrdersVO.executeQuery();

        AdfFacesContext.getCurrentInstance().addPartialTarget(this.getAppointmentOrdersTbl());

        //ViewObject vo1 = getViewObjectByIteratorName("TWCYMTAppointmentOrdersVO1Iterator");

        int count = appointOrdersVO.getRowCount();

        if (count > 0) {   

            bindAdd.setDisabled(false);

            bindDelete.setDisabled(false);

            bindSave.setDisabled(false);

            bindOrdCancel.setDisabled(false);

        }else{

            bindDelete.setDisabled(true);

            bindSave.setDisabled(true);

            bindOrdCancel.setDisabled(true);

            

        }

        AdfFacesContext.getCurrentInstance().addPartialTarget(this.getAppointmentOrdersTbl());

        

        AdfFacesContext.getCurrentInstance().addPartialTarget(this.getBindAdd());

        AdfFacesContext.getCurrentInstance().addPartialTarget(this.getBindDelete());

        AdfFacesContext.getCurrentInstance().addPartialTarget(this.getBindSave());

        AdfFacesContext.getCurrentInstance().addPartialTarget(this.getBindOrdCancel());

        

        AdfFacesContext.getCurrentInstance().addPartialTarget(this.getAppointmentOrdersTbl());

        return null;

    }


    public void revertChangesCurrentRow(Row curRow) {

        if (curRow != null) {

            curRow.refresh(Row.REFRESH_UNDO_CHANGES | Row.REFRESH_WITH_DB_FORGET_CHANGES);

        }

    }

Wednesday, January 4, 2023

Jbo logger enabling

 -Djbo.debugoutput=console





SSL  Settings
admin console Servers -> server name -> Configuration SSL tab -> Advanced -> Change Hostname Verification dropdown to None