Jasface报告集成在Primefaces中

时间:2014-11-11 05:13:40

标签: java jsf primefaces jasper-reports

我发布的代码片段在其他表单上效果很好,可以将Jasperreport打印为Pdf。

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

Backing Bean代码段:

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();
        }

    }

上面的代码在其他表单上运行良好,但是它不能以特定的形式工作,这是一个Dialog.It没有错误,但它也没有给出任何输出。 我带了一些解决方案,但没有工作。

0 个答案:

没有答案