2 Replies Latest reply on Oct 10, 2007 6:40 AM by nemya

    servlet functionality with seam component

    arussel

      Hi,
      I am porting a project to seam.
      We have a servlet that interface with BusinessObjects.
      mapping of *.pdf and *.xls goes to that servlet and it returns rapport from BO in pdf or xls format.
      mapping of *.bo return html of the BO rapport.

      We would like to have a BO component. We're using facelet. Outputing th e html is easy, we put it in a String and use #{theHtmlString}.
      Is there a way to have a link: myRapport.pdf that would call an action from the component and then the component to be able to write to the output steam and set header.

      alex

        • 1. Re: servlet functionality with seam component
          swd847

          I was asking the same question not long ago. Here is an easy way to return a pdf from an action method (in this case a Jasper Report):

          byte[] data = JasperRunManager.runReportToPdf(compileDir
           + report.getReport() + ".jasper", params);
          
           FacesContext facesContext = FacesContext.getCurrentInstance();
           HttpServletResponse response = (HttpServletResponse) facesContext
           .getExternalContext().getResponse();
           response.setContentType("application/pdf");
           response.setContentLength(data.length);
           response.setHeader("Content-disposition",
           "attachment;filename=report.pdf");
          
           try {
          
           OutputStream out = response.getOutputStream();
          
           out.write(data);
          
           out.flush();
           out.close();
          
           facesContext.responseComplete();
           } catch (IOException ex) {
           FacesMessages.instance().add(
           "Error while downloading the file: report.pdf");
           }
          
          


          • 2. Re: servlet functionality with seam component
            nemya

            Alex
            How do you return reports in xls format?