Controller Code:-
Expected Error:-
if TemplateHelper gives error then we need to TemplateHelper class file in "xdo" folder in apps folder in class.
Write Following Code in Controller:-
if (pageContext.getParameter("Report") != null)
{
// OAApplicationModule am = pageContext.getApplicationModule(webBean) ;
DataObject sessionDictionary = (DataObject)pageContext.getNamedDataObject("_SessionParameters");
HttpServletResponse response = (HttpServletResponse)sessionDictionary.selectValue(null,"HttpServletResponse");
String sqlStatement1 = new String();
String pfilename = "JEG_TAX_2015.xls";
// am.invokeMethod("FilterPPStart");
am.invokeMethod("PrintXML");
try {
ServletOutputStream os = response.getOutputStream();
String contentDisposition = "attachment;filename="+pfilename;
response.setHeader("Content-Disposition",contentDisposition);
response.setContentType("application/MSEXCEL");
/// Get the Data XML File as the XMLNode
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
//Starting tag for overall XML
String tag = "<Header>";
byte[] tagBytes = tag.getBytes();
//Write starting tag to outputStream
outputStream.write(tagBytes);
XMLNode xmlNode2 = (XMLNode) am.invokeMethod("getPAXML");
xmlNode2.print(outputStream);
tag = "</Header>";
tagBytes = tag.getBytes();
outputStream.write(tagBytes);
ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
ByteArrayOutputStream pdfFile = new ByteArrayOutputStream();
Properties prop = new Properties();
//Generate the PDF Report.
TemplateHelper.processTemplate(
((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getAppsContext(),
"PO",
"JEG_LCD_TEST1",
((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getUserLocale().getLanguage(),
((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getUserLocale().getCountry(),
inputStream,
TemplateHelper.OUTPUT_TYPE_EXCEL,
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");
System.out.println(e.getMessage());
throw new OAException(e.getMessage(), OAException.ERROR);
}
pageContext.setDocumentRendered(true);
} //if (pageContext.getParameter("Report") != null)
AM Code:-
Create Following Methods In AM
public void PrintXML()
{
try{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
OAViewObject vo = (OAViewObject)findViewObject("EmpVO");
XMLNode xmlNode = (XMLNode)vo.writeXML(4, XMLInterface.XML_OPT_ALL_ROWS);
xmlNode.print(outputStream);
System.out.println(outputStream.toString());
}
catch (Exception e)
{
System.out.println("Error");
}
}
//print xml on the pag
public XMLNode getPAXML()
{
try
{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
OAViewObject vo = (OAViewObject)findViewObject("EmpVO");
XMLNode xmlNode = (XMLNode)vo.writeXML(4, XMLInterface.XML_OPT_ALL_ROWS);
return xmlNode;
// System.out.println(outputStream.toString());
} catch (Exception e)
{
throw new OAException(e.getMessage() + "Custom Error");
}
}
No comments:
Post a Comment