7 Replies Latest reply on Dec 1, 2005 12:29 PM by manuel.gentile

    Some Seam and JasperReports related questions

    drapierwim

      I'm trying out jasperreports(for the first time...) and I must say it's not easy to find some good documentation, to leave that aside I have some problem where I could use some help.

      1, Is it possible to inject the 'ServletContext' if so how can this be done? This is needed to load my compiled report.

      File reportFile = new File(servletContext.getRealPath("/reports/classic.jasper"));


      2. When the report is generated I have an byte arry, since seam components will have a string as return value I will never get to see my report. So this will have to be an JSF Managedbean or are there other ways to deal with that.

      byte[] pdf = JasperExportManager.exportReportToPdf(jasperPrint);


        • 1. Re: Some Seam and JasperReports related questions
          drapierwim

           


          2. When the report is generated I have an byte arry, since seam components will have a string as return value I will never get to see my report. So this will have to be an JSF Managedbean or are there other ways to deal with that.

          Ok, I hate myself for doing that but you can ignore the second question,
          to solve it i can just Outject it into some relevant context and the case is closed.

          Sometimes I can write miles and miles of code, stop and think for a while and ending up in rewriting it in a few lines... stupid isn't it.

          • 2. Re: Some Seam and JasperReports related questions
            gavin.king

            You should be able to get the ServletContext by navigating (and typecasting) from the FacesContext. But I think I'll add a feature to allow the ServletContext to be easily injected. I guess the same goes for HttpSession and HttpRequest....

            • 3. Re: Some Seam and JasperReports related questions
              drapierwim

              Are these the same?

              ServletContext servletContext = (ServletContext) javax.faces.context.FacesContext.getCurrentInstance().getExternalContext().getContext();


              and the @injected seam version

              @In
              private FacesContext facesContext;
              ...
              ServletContext servletContext = (ServletContext) facesContext.getContext().getExternalContext().getContext();


              • 4. Re: Some Seam and JasperReports related questions
                gavin.king

                yes, the are the same

                • 5. Re: Some Seam and JasperReports related questions
                  drapierwim

                  I've managed to generate my report as a byte[], but here comes the
                  problem I don't have a clue on how and where to place my byte[]

                  This is what I found on a jasper report presentation from
                  JBoss World 2005, how should I get a reference to the responce object
                  in my SFSB or are there other and better ways to solve this.

                  response.setContentType("appliction/pdf");
                  response.setContentLength(bytes.length);


                  • 6. Re: Some Seam and JasperReports related questions
                    patrick_ibg

                    You can get to the HttpResponse object via the external web-context via the FacesContext.

                    • 7. Re: Some Seam and JasperReports related questions
                      manuel.gentile

                      Sure! But if i write

                      response.setHeader("Content-disposition",
                      "attachment; filename=report.pdf" );
                      response.setContentType("appliction/pdf");
                      response.setContentLength(pdf.length);
                      ServletOutputStream ouputStream = response.getOutputStream();
                      ouputStream.write(pdf, 0, pdf.length);
                      ouputStream.flush();
                      ouputStream.close();
                      facesContext.responseComplete();

                      i break Seam and at the next operation i have an Exception!!!


                      if i don't write facesContext.responseComplete(); the Seam works but i have the bytes in the response as char....

                      Any solution?