I am using Dynamic Jasper reports 5.0.1 in JSF 2.2 project. The code worked well in JSF 1.2 but not rendering the report to output stream while in JSF 2.2. I am not sure its the up version of frame work or i am doing some thing wrong. Following 2 lines of codes works perfectly well:-
report.show() opens the reports in Jasper Viewer
and report.toPdf(new FileOutputStream("c:/report.pdf")) writes the report to c drive
However following code do nothing at all without any error log:-
//.................................Report Printing Starts...................
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletResponse resp = (HttpServletResponse)facesContext.getExternalContext().getResponse();
facesContext.responseComplete();
JasperReportBuilder report = DynamicReports.report();//a new report
resp.setHeader("Content-disposition", "attachment;");
ServletOutputStream out = resp.getOutputStream();
try
{
report
.setColumnTitleStyle(columnTitleStyle)
.ignorePageWidth()
.highlightDetailEvenRows()
.columns(Col_Array) //where Col_Array is defined as TextColumnBuilder[] Col_Array; and the elements in it display correctly
.title(cmp.text("Offrs Panel").setStyle(boldCenteredStyle))
.pageFooter(cmp.pageXofY().setStyle(boldCenteredStyle))
.setDataSource(createReportDataSource()) // createReportDataSource return a JRDataSource and its valid as it opens in Jasper viewer correctly
//.show() this code works
.toPdf(out) //.............this is problem statement. I want to open a pdf file here in native program like adobe and NOT in jasper viewer (
//.toExcelApiXls(out) showing same behavior and not opening the excel file
//.toPdf(new FileOutputStream("c:/report.pdf")); this code works too
}
catch (Exception e)
{
e.printStackTrace();
}
out.flush();
out.close();
//.................................Report Printing Ends...................
Please rectify what else is required.