This is possible to do fairly easily, here's some sample code:

        FacesContext facesContext = Utils.getFacesContext();
        HttpServletResponse response = (HttpServletResponse) facesContext
                .getExternalContext().getResponse();
        try {
            response.setContentType(attachment.getContentType());
            response.setHeader("Content-disposition", "inline;filename=" 
                    + attachment.getName());
            response.getOutputStream().write(attachment.getDocument());
        }
        catch (IOException e) {
            System.out.println(e);
        }
        facesContext.responseComplete(); 

The above code is in a utility we can call anywhere we need it, but it's called 
by an action when a user chooses to view an attachment.

Our Attachment object has the following methods:

   String getContentType()
   String getName()
   byte[] getDocument();

You could do something similar using Poi (to generate and output a spreadsheet).

----------------------------------------------
Neal Haggard
Senior Systems Developer
Knowledge Management Center
SAS Institute

-----Original Message-----
From: CONNER, BRENDAN (SBCSI) [mailto:[EMAIL PROTECTED] 
Sent: Friday, October 21, 2005 3:29 PM
To: MyFaces Discussion
Subject: FileDownload capability?

We have an application requirement saying that the user needs the ability to 
push a button on our report page to download the report data into a local file 
on the user's machine suitable for loading into a spreadsheet.  How can 
something like this be done?

- Brendan

Reply via email to