title: JasperReports can't export data with JSF 2 and PrimeFaces 3.5
body: <p>I am developing an application with <em>PrimeFaces 3.5</em>, <em>JasperReports 5.2</em>, and <em>JSF 2.x</em>. I have some report pages in my old application prepared by <em>JasperReports 4.5</em> and <em>JSF 1.2</em>. All those report pages are working in the old application. I tried to transfer those report pages in my new application. Everything works fine in the new app but report cannot be exported and I don't get any error. Am I missing something? </p>
  
  <p>Here is my code that works perfectly in my old <em>Jsf 1.2</em> app but not with the new app. </p>
  
  <pre><code>private void prepareReport(String reportPath, @SuppressWarnings("rawtypes") List beanList, String outputFormat, String reportName) {
      JasperReport jReport = null;
      JasperPrint jPrint = null;
      try {
          jReport = JasperCompileManager.compileReport(reportPath);
          jPrint = JasperFillManager.fillReport(jReport, jasperParameter, new JRBeanCollectionDataSource(beanList));
      } catch (JRException e) {
          e.printStackTrace();
      }
  
      FacesContext ctx = FacesContext.getCurrentInstance();
      HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();
      OutputStream outputStream = null;
  
      try {
          outputStream = response.getOutputStream();
      } catch (IOException e) {
          e.printStackTrace();
      }
  
      try {
          if (outputFormat.equals(OUTPUT_FORMAT_PDF)) {
              response.setContentType("application/pdf");
              response.setHeader("Content-disposition", "attachment; filename=" + reportName + ".pdf");
              JasperExportManager.exportReportToPdfStream(jPrint, outputStream);
          } else if (outputFormat.equals(OUTPUT_FORMAT_EXCEL)) {
              response.setContentType("application/xls");
              response.setHeader("Content-disposition", "attachment; filename=" + reportName + ".xls");
              JExcelApiExporter exporter = new JExcelApiExporter();
              exporter.setParameter(JRExporterParameter.JASPER_PRINT, jPrint);
              exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream);
              exporter.exportReport();
          } else if (outputFormat.equals(OUTPUT_FORMAT_RTF)) {
              response.setContentType("application/rtf");
              response.setHeader("Content-disposition", "attachment; filename=" + reportName + ".rtf");
              JRRtfExporter exporter = new JRRtfExporter();
              exporter.setParameter(JRExporterParameter.JASPER_PRINT, jPrint);
              exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream);
              exporter.exportReport();
          }
      } catch (JRException e) {
          e.printStackTrace();
      }
  
      try {
          outputStream.flush();
          outputStream.close();
          FacesContext.getCurrentInstance().responseComplete();
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>Here is part of the JSF 2 xhtml page that I call the backing bean:</p>
  
  <pre><code>&lt;h:panelGrid columns="4" columnClasses="alignTop,alignTop,alignTop,alignTop"&gt;
      &lt;p:commandButton id="pdfFormatBtn" actionListener="#{reports.pdfFormatSelected}" value="PDF" immediate="true"
          icon="pdfIcon" styleClass="tableCell"/&gt;
      &lt;p:commandButton id="excelFormatBtn" actionListener="#{reports.pdfFormatSelected}" value="EXCEL" immediate="true"
          icon="excelIcon" styleClass="tableCell"/&gt;
      &lt;p:commandButton id="rtfFormatBtn" actionListener="#{reports.pdfFormatSelected}" value="RTF" immediate="true"
          icon="rtfIcon" styleClass="tableCell"/&gt;
      &lt;p:commandButton id="cleanBtn" actionListener="#" value="#{general.clean}" immediate="true"
          icon="ui-icon-refresh" styleClass="tableCell"/&gt;
  &lt;/h:panelGrid&gt;
  </code></pre>