Anil's Blog is Best Viewed on GOOGLE CHROME

Sunday, January 11, 2015

Integrate XML Publisher Report with OAF


In this example we are going to integrate a simple XML publisher report with OAF. The business scenario is something like that we have a OAF page and on click of "Print" button we want to call a XML publisher report.

Steps
1. Create a OAF page with table region and print button to call a XML publisher report.


2. Designed XML report template. here I have not mentioned steps to register the XML report in Oracle apps.



Controller Code
Here we are handling the print button action and calling the XML report.
    public void processFormRequest(OAPageContext pageContext, 
                                   OAWebBean webBean) {
        super.processFormRequest(pageContext, webBean);
        if (pageContext.getParameter("Print") != null) {

            System.out.println("Print Button clicked");

            printReport(pageContext, webBean, "pdf");

        }

    public void printReport(OAPageContext pageContext, OAWebBean webBean, 
                            String outputType) {

        OAApplicationModule lo_am = pageContext.getApplicationModule(webBean);
        
        String ls_extensionType = "pdf"; //Setting the output extension type
        byte l_outputType = 0;
        l_outputType = TemplateHelper.OUTPUT_TYPE_PDF;


        DataObject lo_sessionDictionary = 
            pageContext.getNamedDataObject("_SessionParameters");
        HttpServletResponse lo_response = 
            (HttpServletResponse)lo_sessionDictionary.selectValue(null, 
                                                                  "HttpServletResponse");
        try {
            ServletOutputStream lo_outputStream = 
                lo_response.getOutputStream();

            // setting the report name & output type
            String lo_contentDisposition = 
                "attachment;filename=OrderDetails." + ls_extensionType;
            lo_response.setHeader("Content-Disposition", 
                                  lo_contentDisposition);
            lo_response.setContentType("application/pdf");

            System.out.println("Calling XML generation method");

            XMLNode xmlNode = 
                (XMLNode)lo_am.invokeMethod("getOrderReportDetailsXML");
            // Calling getOrderReportDetailsXML method to get the XML for the VO query

            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

            xmlNode.print(outputStream);
            System.out.println("After calling XML generation method" + 
                               outputStream.toString());
            //Above sop will return the XML output which will help you in designing the template.
 
            ByteArrayInputStream lo_inputStream = 
                new ByteArrayInputStream(outputStream.toByteArray());
            ByteArrayOutputStream lo_outputFile = new ByteArrayOutputStream();
            
            // Pass the Template code and Application short name
            try {
                TemplateHelper.processTemplate(((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getAppsContext(), 
                                               "PA", "XX_ORDER_DT", 
                                               ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getUserLocale().getLanguage(), 
                                               ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getUserLocale().getCountry(), 
                                               lo_inputStream, l_outputType, 
                                               null, lo_outputFile);

            } catch (XDOException xe) {
                throw new OAException("Exception:" + xe.getMessage());

            }

            byte[] l_bytes = lo_outputFile.toByteArray();

            lo_response.setContentLength(l_bytes.length);
            lo_outputStream.write(l_bytes, 0, l_bytes.length);
            lo_outputStream.flush();
            lo_outputStream.close();
        } catch (Exception e) {
            lo_response.setContentType("text/html");
            throw new OAException(e.getMessage(), OAException.ERROR);
        }
        pageContext.setDocumentRendered(false);

    }

Application Module Code

 This method will return the XML output of the VO query attached to the page.

   public XMLNode getOrderReportDetailsXML() {
        //XMLNode lo_xmlNode;
       System.out.println("Inside the AM Method");
        OrderReportDetailsVOImpl vo = getOrderReportDetailsVO1();
            vo.executeQuery();
          XMLNode  lo_xmlNode = (XMLNode)vo.writeXML(-1, 0L);

//OL Stands for XMLInterface.XML_OPT_ALL_ROWS which means to includes all rows in the view object's row set in the XML.

        return lo_xmlNode;
    }


Report Output


Thanks,
 --Anil

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.