Tuesday, July 5, 2016

Integrating XML Publisher and OAF To get Output In PDF file

To generate the output in PDF formats we need the following:

1 Design the OAF BC4J Object.
2) Design the OAF Page and generate the Data XML
3) Design the RTF Template using Data XML
4) Register the Template with Oracle Applications.
5) Integrating the OAF page With XML Publisher.
6) Invoking the report from OAF

Expected Error:-
if TemplateHelper gives error then we need to TemplateHelper class file in "xdo" folder in apps folder in class.



//In AMImpl.java

    public XMLNode  getPrintDataXML()

    {
    
       

     try

     {

       ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

              // Below Created Object For VO
          OAViewObject vo = getPodetailVO(); 
          
          //Below Code To print xml code in jdevloper

       ((XMLNode) vo.writeXML(4, XMLInterface.XML_OPT_ALL_ROWS)).print(outputStream);

       System.out.println(outputStream.toString());
       
       // below to return xml code for this method.
       
          XMLNode xmlNode = (XMLNode) vo.writeXML(4, XMLInterface.XML_OPT_ALL_ROWS);
          return xmlNode;

      }

     catch(Exception e)

     {

      throw new OAException (e.getMessage());

     }


    } 


// In Controller 

              if(pageContext.getParameter("Print") != null)
              {
              
              
              // Get the HttpServletResponse object from the PageContext. The report output is written to HttpServletResponse.
              DataObject sessionDictionary = (DataObject)pageContext.getNamedDataObject("_SessionParameters");
              HttpServletResponse response = (HttpServletResponse)sessionDictionary.selectValue(null,"HttpServletResponse");
              
              
              try {
              
              ServletOutputStream os = response.getOutputStream();

              // Set the Output Report File Name and Content Type
              String contentDisposition = "attachment;filename=krishna.pdf";
              response.setHeader("Content-Disposition",contentDisposition);
              response.setContentType("application/pdf");
              

              // Get the Data XML File as the XMLNode

              XMLNode xmlNode = (XMLNode) am.invokeMethod("getPrintDataXML");


              ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
              xmlNode.print(outputStream);
              ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
              ByteArrayOutputStream pdfFile = new ByteArrayOutputStream();
              

              //Generate the PDF Report.
              TemplateHelper.processTemplate(
              ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getAppsContext(),
              "FND",// Application Short Name
              "PO_Search_OAF", // Data Template Short Name
              ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getUserLocale().getLanguage(),
              ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getUserLocale().getCountry(),
              inputStream,TemplateHelper.OUTPUT_TYPE_PDF,null,pdfFile);
              

              // Write the PDF Report to the HttpServletResponse object and flush.
              byte[] b = pdfFile.toByteArray();
              response.setContentLength(b.length);
              os.write(b, 0, b.length);
              os.flush();
              os.close();
              
              
              }
              catch(Exception e)
              {
              response.setContentType("text/html");
              throw new OAException(e.getMessage(), OAException.ERROR);
              } 
              pageContext.setDocumentRendered(true);


              }

Monday, July 4, 2016

How To Call PL/SQL Procedures and Functions In OAF


Create Method In AM Java Code:-

  
 public String AddNumber(String item1,String item2)
        {
       
            OADBTransaction oadbtransaction = (OADBTransaction)getTransaction();
                  OADBTransactionImpl oadbtransactionimpl = (OADBTransactionImpl)getTransaction();
                 String retValues;
               
        // Below I hava created Strring to Call Pl/sql procedure in Begin and end block        
        String str = "Begin proc_in_oaf.addition(:1,:2,:3); End;";

        OracleCallableStatement oraclecallablestatement =
                  (OracleCallableStatement)oadbtransaction.createCallableStatement(str.toString(), 1);
               
                 try{
                  oraclecallablestatement.setFloat(1,  Float.parseFloat(item1)  );
                  oraclecallablestatement.setFloat(2,  Float.parseFloat(item2) );
                  oraclecallablestatement.registerOutParameter(3,Types.VARCHAR);
                  oraclecallablestatement.execute();
                                 
                  retValues = oraclecallablestatement.getString(3);
                 }
                 catch(Exception e)
                 {
                  throw OAException.wrapperException(e);
                 }
               
               
               
                 return retValues;
               
        }


Call Method In Controller:-


//CalculationAMImpl it is AM name


 CalculationAMImpl am1 = (CalculationAMImpl)pageContext.getApplicationModule(webBean);


    OAMessageTextInputBean xx = (OAMessageTextInputBean)webBean.findIndexedChildRecursive("item2");
   
    OAMessageTextInputBean xx1 = (OAMessageTextInputBean)webBean.findChildRecursive("item7");
   
          Serializable[] parameters1 = { (Serializable)xx.getValue(pageContext), (Serializable)xx1.getValue(pageContext) };

//here I have Called That Method
   
    String no = (String)am1.invokeMethod("AddNumber",parameters1);

Steps to implement Subtab Region in OAF

Steps to implement Subtab Region in OAF :
Assuming ApplicationShortName = XXCUS
1.    Create a Page XXCUSSubtabPG
2.    From Page layout Region , create a new region , set region style as subTabLayout .
3.    In property Pallette under Visual , Initial Subtab = {mention the value : 0 if you want to show the 1st tab as default , 1 if you want to show the 2nd tab as default}
4.    Right Click SubTabRN and create as many regions as you want the tabs to be displayed
5.    Right click on SubTabRN and Click on Subtabs it defaults subTabBar under subTablayoutComponents
6.    Create links as many regions that you created
7.    Set destination URI property for links as                                                                                                          OA.jsp?page=/myCompany/oracle/apps/xxcus/Subname/webui/XXCUSSubtabPG&retain AM='Y'"+"&"+OASubTabLayoutBean.OA_SELECTED_SUBTAB_IDX+"="+6.
8.    Set the Visual Prompt Value for the links.
Subname is optional 


Note : No . of links under SubtabLayout = Number of Regions under SubTabRN


Used Below Code While Creating Subtab Region Page:-


OA.jsp?page=/Krishna/oracle/apps/ak/xxtr/Cal/webui/CalcPG&retainAM=Y&addBreadCrumb=Y"+"&" +OASubTabLayoutBean.OA_SELECTED_SUBTAB_IDX + "=" + 0