I have report1.jrxml which have simple SQL query with no parameters and runs fine in iReport. I want to open this report through ADF.
my reportAction method is as follows:
public void reportAction(FacesContext ctx,OutputStream output) throws FileNotFoundException,NamingException,
SQLException, IOException, JRException,
ClassNotFoundException,
InstantiationException,
IllegalAccessException {
File input = null;
Connection conn = null;
Map reportParameters = new HashMap();
bindings = this.getBindings();
ctx = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse)ctx.getExternalContext().getResponse();
String reportPath = ctx.getExternalContext().getInitParameter("reportpath");
input = new File(reportPath+"report1.jasper");
if(bindings!=null){
OperationBinding ob = bindings.getOperationBinding("getCurrentConnection");
ob.execute();
conn = (Connection)ob.getResult();
if(input.getPath()!=null&&reportParameters!=null&&conn!=null){
JasperPrint print = JasperFillManager.fillReport(input.getPath(),reportParameters,conn);
response.addHeader("Content-disposition", "attachment;filename=report1.pdf");
output = response.getOutputStream();
String userName = "ilpa";
File outPutPDF = new File("D:/jdev libs/reports/report1.pdf");
JasperExportManager.exportReportToPdfStream(print, output);
JasperExportManager.exportReportToPdfFile(print,outPutPDF.getPath());
JasperExportManager.exportReportToPdfStream(print, output);
output.flush();
output.close();
}
}
else{
ctx.addMessage(null,new FacesMessage("No bindings configured for this page"));
}
}
What could be wrong?
I have solved the issue myself.
The root cause was I was giving a wrong path in web.xml.
That is, I had report1.jrxml in two locations. The actual report I was using was in a different location.