1

I am posting a code snippet which worked well on other forms to print Jasperreport as Pdf.

<p:commandButton id="cmdPrint" value="Print"
    actionListener="#{receiptMB.print()}"
    disabled="#{receiptMB.chkSave == false}" process="@this" />

Backing Bean code snippet :

public void print(){

        try
        {
        JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(getObjPrintList());

        String  reportPath=  FacesContext.getCurrentInstance().getExternalContext().getRealPath("/reports/Receipt.jasper");     

        JasperPrint jasperPrint=JasperFillManager.fillReport(reportPath,getReportParameters(), beanCollectionDataSource);  

        HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
        httpServletResponse.setContentType("application / pdf");
        httpServletResponse.addHeader("Content-disposition", "inline; filename=Receipt_" +objPrint.getDateNp()+".pdf");
        ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream();

        servletOutputStream.write(JasperExportManager.exportReportToPdf(jasperPrint));
        servletOutputStream.flush();
        servletOutputStream.close();
        FacesContext.getCurrentInstance().renderResponse();
        FacesContext.getCurrentInstance().responseComplete();
        }
        catch(JRException e){
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

The above code is working well on other forms but it is not working in a particular form which is a Dialog.It gives no error but, also it doesn't give any output. I went around with some solutions but no work.

SudeepShakya
  • 571
  • 3
  • 14
  • 34

0 Answers0