Problems with lentidao when generating a jasper report

0

I have a problem, every time I generate a report for the first time, it takes time to generate, since the second time it goes very fast, I am sending the code that generates the report if someone can help. >

  public void relatorioUSALL(List lista, String tipo, Map param, String tip, String nomrel) {
    try {
        FacesContext context = FacesContext.getCurrentInstance();
        HttpServletResponse response = (HttpServletResponse) context
                .getExternalContext().getResponse();
        ServletOutputStream responseStream = response.getOutputStream();
        String path = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/Report/" + tipo + ".jrxml");

        //InputStream pathjrxml = getClass().getResourceAsStream(path);
        //String path = ("C:\Users\Administrator\Desktop\glassfish4\glassfish\domains\domain1\applications\Hibernate\Report\" + tipo + ".jrxml" );
        if (tip.equals("0")) {
            response.setContentType("application/pdf");
            response.setHeader("Content-Disposition", "inline; filename=\"" + nomrel + ".pdf\"");
            JasperReport pathReport = JasperCompileManager
                    .compileReport(path);
            JasperPrint print = JasperFillManager.fillReport(pathReport, param,
                    new JRBeanCollectionDataSource(lista));

            JasperExportManager.exportReportToPdfStream(print, responseStream);
            responseStream.flush();
            responseStream.close();
            context.renderResponse();
            context.responseComplete();
        } else if (tip.equals("1")) {
            response.setContentType("application/pdf");
            response.setHeader("Content-Disposition", "attachment; filename=\"" + nomrel + ".pdf\"");
            JasperReport pathReport = JasperCompileManager
                    .compileReport(path);
            JasperPrint print = JasperFillManager.fillReport(pathReport, param,
                    new JRBeanCollectionDataSource(lista));

            JasperExportManager.exportReportToPdfStream(print, responseStream);
            responseStream.flush();
            responseStream.close();
            context.renderResponse();
            context.responseComplete();

        } else if (tip.equals("3")) {
            response.setContentType("application/ms-excel");
            response.addHeader("Content-disposition", "attachment; filename=" + nomrel + ".xls");
            JasperReport pathReport = JasperCompileManager
                    .compileReport(path);

            JasperPrint print = JasperFillManager.fillReport(pathReport, param,
                    new JRBeanCollectionDataSource(lista));
            ServletOutputStream servletOutputStream = response.getOutputStream();

            JRExporter exporterXLS = new JRXlsExporter();
            exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT, print);
            exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, servletOutputStream);
            exporterXLS.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE);
            exporterXLS.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
            exporterXLS.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
            exporterXLS.setParameter(JRXlsExporterParameter.CHARACTER_ENCODING, "UTF-8");
            exporterXLS.exportReport();
            responseStream.flush();
            responseStream.close();
            context.renderResponse();
            context.responseComplete();
        } else if (tip.equals("2")) {
            response.addHeader("Content-disposition", "attachment; filename=" + nomrel + ".docx");
            JasperReport pathReport = JasperCompileManager
                    .compileReport(path);

            JasperPrint print = JasperFillManager.fillReport(pathReport, null,
                    new JRBeanCollectionDataSource(lista));
            ServletOutputStream servletOutputStream = response.getOutputStream();
            JRDocxExporter docxExporter = new JRDocxExporter();
            docxExporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
            docxExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, servletOutputStream);
            docxExporter.exportReport();
            FacesContext.getCurrentInstance().responseComplete();

        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}
    
asked by anonymous 22.03.2016 / 17:47

0 answers