3 Replies Latest reply on Nov 22, 2006 5:38 AM by Reinhard Behrens

    Seam+JSF - File Download through HttpServletResponse problem

    Reinhard Behrens Newbie


      I reference my external context as per http://www.jboss.org/index.html?module=bb&op=viewtopic&t=94163
      but it does not function the way I thought.

      If I create the PDF argument for my action function from a DataModelSelection, then the action should prompt the user to either download or view the test pdf1.pdf when clicked.

      The file reading and output works fine, just not to the ServletOutputStream. It returns "Success" without any errors or Exceptions on my JBoss
      console output.

      Am I missing something? Does the function return value have something to do with it, pageflow etc... ?

      Any help would be appreciated.

      The code :

      public class DownloadPDFAction implements DownloadPDF{
       private EntityManager em;
       private ExternalContext extCtx;
       private PDF pdf;
       public String download(PDF pdf)
       String filePath = null;
       String fileName = null;
       int read = 0;
       byte[] bytes = new byte[1000];
       HttpServletResponse response = (HttpServletResponse)extCtx.getResponse();
       response.addHeader("Content-disposition", "attachment; filename=\"" + fileName +"\"");
       filePath = "C:\\";
       fileName = "pdf1.pdf";
       ServletOutputStream os = response.getOutputStream();
       File file = new File(filePath,fileName);
       FileInputStream fis = new FileInputStream(file);
       while((read = fis.read(bytes)) != -1)
       catch(Exception e)
       System.out.println("\nFailure : " + e.toString() + "\n");
       return "main";
       @Destroy @Remove
       public void destroy(){}

      The JSF :
      <h:dataTable value="#{pdfs}" var="d_map" rendered="#{pdfs.rowCount > 0}">
       <s:link value="Document : #{d_map.name}" action="#{downloadpdf.download(d_map)}"/><img width="16" height="17" src="img/acrobat.jpg" />