1

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.

learner
  • 757
  • 2
  • 14
  • 35
  • Could it be that `attachment;` is not enough information for the browser? Instead maybe add a filename ending with pdf, e.g. `attachment; filename=download.pdf` (see more [here](http://stackoverflow.com/questions/9195304/how-to-use-content-disposition-for-force-a-file-to-download-to-the-hard-drive)). – tobi6 Jul 11 '16 at 08:18
  • I tried. But no luck. It keeps on opening in Jasper Viewer while Excel file does not opens at all. BUMP. – learner Jul 14 '16 at 15:28
  • There is no bumping on SO. So to understand this correctly, you request a download in your browser and the result *will open Jasper Viewer and display the PDF*? What about other files? To your other question: The API [clearly states](http://apidocs.dynamicreports.org/) `toExcelApiXls` as *deprecated*, you should use `toXls`. – tobi6 Jul 15 '16 at 13:49
  • Ok. wont bump again. about the problem, is toPdf depricated to? my issue is...the report opens in jasper viewer when i use toPdf while toExcelApiXls / toXls both does nothing at all. cant be more elaborate. – learner Jul 16 '16 at 16:31
  • Still not clear in how the workflow and the infrastructure is. Please answer the questions as well as: Where is your server? On the same machine as the client? – tobi6 Jul 17 '16 at 08:19

0 Answers0