Controller Code
================================================
// Import below classes in Controller
import java.util.Properties;import oracle.apps.xdo.oa.common.DocumentHelper;
import java.io.ByteArrayOutputStream;
import java.io.Serializable;
import java.util.Properties;
import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.xdo.oa.common.DocumentHelper;
import oracle.apps.xdo.oa.schema.server.Template;
import oracle.jbo.XMLInterface;
import oracle.jbo.domain.BlobDomain;
import oracle.xml.parser.v2.XMLNode;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import oracle.apps.xdo.XDOException;
import oracle.apps.xdo.oa.schema.server.TemplateHelper;
import oracle.cabo.ui.data.DataObject;
import oracle.jbo.XMLInterface;
import oracle.apps.xdo.oa.schema.server.Template;
import oracle.jbo.domain.BlobDomain;
....
....
....
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processFormRequest(pageContext, webBean);
OAApplicationModule am = pageContext.getApplicationModule(webBean);
////////////////////////////////////////
///////// For RTF Template
////////////////////////////////////////
if ((pageContext.getParameter("BTNPrintReport") != null)) {
String TemplateApplicationShortName = "PER";
String TemplateCode = "XXARMSEMP"; //"XXARMS_IR_InterviewFeedback" ;
Number LeadId = 494;
Serializable aserializable2[] = {LeadId.toString()};
Class aclass2[] = {String.class };
BlobDomain result = (BlobDomain) am.invokeMethod("getXMLData",aserializable2,aclass2);
// 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=EmpReport.pdf";
response.setHeader("Content-Disposition",contentDisposition);
response.setContentType("application/pdf");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
outputStream = (ByteArrayOutputStream)result.getOutputStream();
ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
ByteArrayOutputStream pdfFile = new ByteArrayOutputStream();
//Generate the PDF Report.
TemplateHelper.processTemplate(
((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getAppsContext(),
TemplateApplicationShortName,
TemplateCode,
((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(false);
}
}
Application Module Code
================================================
public BlobDomain getXMLData(String P_VacancyId)
{
BlobDomain blobDomain = new BlobDomain();
OADBTransaction oadbtransaction = getOADBTransaction();
try
{
String dataDefCode = "XXARMSEMP"; //"XXARMSInterviewFeedback" ;
String dataDefApp = "PER";
String outputString = null;
DataTemplate datatemplate = new DataTemplate(((OADBTransactionImpl)getOADBTransaction()).getAppsContext(), dataDefApp, dataDefCode );
// Hashtable parameters = new Hashtable();
// parameters.put("P_VacancyId",P_VacancyId);
// datatemplate.setParameters(parameters);
datatemplate.setOutput(blobDomain.getBinaryOutputStream());
datatemplate.processData();
}
catch(SQLException e)
{
throw new OAException("SQL Error=" + e.getMessage(),OAException.ERROR);
}
catch (XDOException e)
{
throw new OAException("XDOException" + e.getMessage(),OAException.ERROR);
}
catch(Exception e)
{
throw new OAException("Exception" + e.getMessage(),OAException.ERROR);
}
return blobDomain;
}