11 Replies Latest reply on Jun 1, 2009 4:28 PM by Nick Belaevski

    RF + JasperReports

    Serhiy Zastavnyy Novice

      Hi
      I am trying to run simple JasperReport.
      When I saved it into file everything works fine.
      But, I want browser propose user to download report.

      There is modalPanel, there is HtmlAjaxCommandButton on panel.
      There is action attached to the button.

      It is my code:

      ServletOutputStream out = ((HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse()).getOutputStream()
      
      byte[] bytes = null;
      ((HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse()).setContentType("application/pdf");
      
      JasperReport rep = getJasperReportObject(md);
      if (rep == null)
       return "";
      
      bytes = JasperRunManager.runReportToPdf(rep, new HashMap(), new JREmptyDataSource());
      out.write(bytes, 0, bytes.length);
      
      ((HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse()).setContentLength(bytes.length);
      
      ((HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse()).addHeader("Content-Disposition", "attachment; filename=" + md.getClassName() + ".pdf");
      
      out.flush();
      out.close();
      
      FacesContext.getCurrentInstance().getExternalContext().redirect(RichHelper.getRequest().getContextPath() + PORTAL_PAGE);
      FacesContext.getCurrentInstance().responseComplete();


      Page refreshed, but no request to download file.
      I am new to RF and to JasperReport, please help me. What I am doing wrong.