Controller
=============================================
import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.OAViewObject;
import java.io.Serializable;
import oracle.apps.fnd.framework.webui.OADecimalValidater;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageTextInputBean;
import oracle.cabo.ui.validate.Formatter;
import oracle.apps.fnd.framework.OAException;
import oracle.apps.fnd.framework.webui.beans.OARawTextBean;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import oracle.apps.fnd.framework.server.OADBTransactionImpl;
import oracle.apps.xdo.XDOException;
import oracle.apps.xdo.oa.schema.server.TemplateHelper;
import oracle.apps.xxbg.bgcpxreq.server.CpxReqAMImpl;
import oracle.cabo.ui.data.DataObject;
import oracle.xml.parser.v2.XMLNode;
/*
if (pageContext.getParameter("PrintReport") != null)
{
OAApplicationModule am = pageContext.getApplicationModule(webBean);
String REQNO = pageContext.getParameter("ParamHeaderID");
System.out.println("Req no is :" + REQNO);
Serializable[] params = { REQNO };
am.invokeMethod("initGenerateXMLData", params);
} */
if (pageContext.getParameter("PrintReport") != null) {
System.out.println (" Vishal Generate Report Is Clicked");
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("Vishal Calling XML generation method");
String REQNO = pageContext.getParameter("ParamHeaderID");
System.out.println("Req no is :" + REQNO);
Serializable[] params = { REQNO };
XMLNode xmlNode = (XMLNode)am.invokeMethod("getOrderReportDetailsXML" , params);
// 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();
System.out.println("Vishal 1");
// Pass the Template code and Application short name
try {
System.out.println("Vishal 2");
TemplateHelper.processTemplate(((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getAppsContext(),
"AR",//APPLICATION SHORT NAME
"XXCAPEXREQUESTRPT", //TEMPLATE_SHORT_CODE
((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getUserLocale().getLanguage(),
((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getUserLocale().getCountry(),
lo_inputStream,
TemplateHelper.OUTPUT_TYPE_PDF,
null,
lo_outputFile);
System.out.println("Vishal 3");
} catch (XDOException xe) {
throw new OAException("Exception Vishal 4:" + xe.getMessage());
//System.out.println("Vishal 4");
}
System.out.println("Vishal 5");
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 (AM)
===============================================
import java.io.IOException;
import java.io.OutputStream;
import oracle.apps.fnd.framework.OAException;
import oracle.apps.fnd.framework.server.OAApplicationModuleImpl;
import oracle.apps.fnd.framework.server.OAViewObjectImpl;
import oracle.jbo.Row;
import oracle.apps.fnd.framework.OAViewObject;
import java.sql.CallableStatement;
import java.sql.SQLException;
import java.sql.Types;
import oracle.apps.fnd.framework.OARow;
import oracle.jbo.XMLInterface;
import oracle.jbo.domain.BlobDomain;
import oracle.xml.parser.v2.XMLNode;
public void initGenerateXMLData(String PHeaderID)
{
System.out.println("Entered the init Gen XML Method");
AssetDispDetailsVOImpl vo = getAssetDispDetailsVO1();
System.out.print("its here " + PHeaderID);
Integer PHeadID = Integer.valueOf(Integer.parseInt(PHeaderID));
if (!vo.isPreparedForExecution()) {vo.executeQuery();}
vo.clearCache();
vo.setWhereClause("1=2");
vo.setWhereClauseParams(null);
vo.setWhereClause("REQUEST_NUMBER=:1");
vo.setWhereClauseParam(0, PHeadID);
vo.executeQuery();
XMLNode xmlData = (XMLNode)vo.writeXML(4,XMLInterface.XML_OPT_ALL_ROWS);
BlobDomain blob = new BlobDomain();
OutputStream os=null;
try{ os = blob.getBinaryOutputStream();
xmlData.print(os);
} catch (IOException e) {} catch (SQLException e) {}
System.out.println(os.toString());
}
public XMLNode getOrderReportDetailsXML(String PHeaderID) {
//XMLNode lo_xmlNode;
System.out.println("Inside the AM Method");
AssetDispDetailsVOImpl vo = getAssetDispDetailsVO1();
Integer PHeadID = Integer.valueOf(Integer.parseInt(PHeaderID));
if (!vo.isPreparedForExecution()){vo.executeQuery();}
vo.clearCache();
vo.setWhereClause("1=2");
vo.setWhereClauseParams(null);
vo.setWhereClause("REQUEST_NUMBER=:1");
vo.setWhereClauseParam(0, PHeadID);
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;
}
For Multiple Nodes
if (pageContext.getParameter("generateRpt") != null)
{
String po_number = (String)pageContext.getTransactionValue("PO_NUM");
System.out.println("The PO NUmber i s -----------------"+po_number);
Serializable params[] = { fromDate, toDate, docNo, pendingType, reqNo ,po_number}; //
Class paramType[] =
{ String.class, String.class, String.class, String.class,
String.class,String.class }; //
DataObject sessionDictionary = pageContext.getNamedDataObject("_SessionParameters");
HttpServletResponse response = (HttpServletResponse)sessionDictionary.selectValue(null,
"HttpServletResponse");
try
{
System.out.println("Inisde Generate Button Step 2");
ServletOutputStream os = response.getOutputStream();
if (ReportFormat1 != null && !ReportFormat1.equals(""))
{
if (ReportFormat1.equals("PDF"))
{
System.out.println("Inisde Generate Button Step 3");
contentDisposition = "attachment;filename=Quotation Report.pdf";
response.setHeader("Content-Disposition", contentDisposition);
response.setContentType("application/pdf");
bt = TemplateHelper.OUTPUT_TYPE_PDF;
}
if (ReportFormat1.equals("XLS"))
{
System.out.println("Inisde Generate Button Step 4");
contentDisposition = "attachment;filename=Quotation Report.xls";
response.setHeader("Content-Disposition", contentDisposition);
response.setContentType("application/vnd.ms-excel");
bt = TemplateHelper.OUTPUT_TYPE_EXCEL;
}
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte bufutf[] ="<Testing>".getBytes();
outputStream.write(bufutf);
XMLNode xmlNode[] = new XMLNode[10];
xmlNode = (XMLNode[])am.invokeMethod("executeReportPO",params,paramType);
System.out.println(" IN CO");
xmlNode[1].print(outputStream);
xmlNode[2].print(outputStream);
byte bufutf1[] ="</Testing>".getBytes();
outputStream.write(bufutf1);
System.out.println("Testying in ----------------"+outputStream.toString());
ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
ByteArrayOutputStream fileData = new ByteArrayOutputStream();
TemplateHelper.processTemplate(((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getAppsContext(),
APP_NAME, TEMPLATE_CODE,
((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getUserLocale().getLanguage(),
((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getUserLocale().getCountry(),
inputStream, bt, null, fileData);
System.out.println("Inside template code");
byte[] b = fileData.toByteArray();
response.setContentLength(b.length);
os.write(b, 0, b.length);
os.flush();
os.close();
System.out.println("Inside template code1");
}
catch (Exception e)
{
throw new OAException(e.getMessage());
}
}
AM Code :
public XMLNode[] executeReportPO(String fromDate, String toDate,
String docNo, String pendingType,
String reqNo, String ponum)
{
System.out.println("Inisde Generate Button in AM Step 1" + ponum);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ItemPendingPoVOImpl vo = getItemPendingPoVO1();
PoDetailVOImpl vo1 = getPoDetailVO1();
try
{
vo.setWhereClauseParams(null);
vo.setWhereClauseParam(0, docNo);
vo.setWhereClauseParam(1, reqNo);
vo.setWhereClauseParam(2, fromDate);
vo.setWhereClauseParam(3, toDate);
vo.setWhereClauseParam(4, pendingType);
vo.executeQuery();
System.out.println("Query ---" + vo.getQuery());
String whereconditionpo = "PONO='" + ponum + "'";
vo1.setWhereClause(whereconditionpo);
vo1.executeQuery();
System.out.println("Query 2 --->" + vo1.getQuery());
System.out.println("Inisde Generate Button Step 2 in AM");
} catch (Exception e)
{
throw new OAException(e.getMessage());
}
int s = vo.getRowCount();
System.out.println("fected row count" + s);
XMLNode NodeList[] = new XMLNode[10];
try
{
NodeList[1] = ((XMLNode)vo.writeXML(4, XMLInterface.XML_OPT_ALL_ROWS));
((XMLNode)vo.writeXML(4,
XMLInterface.XML_OPT_ALL_ROWS)).print(outputStream);
System.out.println(outputStream.toString());
System.out.println("Inisde Generate Button Step 1");
NodeList[2] = ((XMLNode)vo1.writeXML(4, XMLInterface.XML_OPT_ALL_ROWS));
((XMLNode)vo1.writeXML(4,
XMLInterface.XML_OPT_ALL_ROWS)).print(outputStream);
System.out.println(outputStream.toString());
return NodeList;
} catch (Exception e)
{
throw new OAException(e.getMessage());
}
}