No, the data being downloaded in the example below is read from the database. The "attachment;filename=" header just provides a default suggested file name for browsers that implement it. You can write out any data you like. You can generate it on the spot if you want. I have a similar control under struts that creates CSV data from the table rows.
On 10/21/05, CONNER, BRENDAN (SBCSI) <[EMAIL PROTECTED]> wrote: > Thanks. In your example, does one have to first write out the data to a > file on the server? I see you set the header with > attachment;filename=..., but then I also see that you have > responseStream.write(selectedContent.getContentDate().getData()). > > - Brendan > > -----Original Message----- > From: Mike Kienenberger [mailto:[EMAIL PROTECTED] > Sent: Friday, October 21, 2005 2:41 PM > To: MyFaces Discussion > Subject: Re: FileDownload capability? > > > Here's one way. > > Note that facesContext.getResponseStream() is only valid during the > render-response phase, so you'll have to access the HttpRequest > directly (not sure how it works for portlets). > > > public String downloadContentData() > { > Content selectedContent = > (Content)this.announcementContentDataList.getRowData(); > FacesContext facesContext = FacesContext.getCurrentInstance(); > // OutputStream responseStream = > facesContext.getResponseStream(); > > try > { > OutputStream responseStream = > ((HttpServletResponse)facesContext.getExternalContext().getResponse()).g > etOutputStream(); > if (null == responseStream) throw new > AbortProcessingException("responseStream is null"); > > HttpServletResponse response = > (HttpServletResponse)facesContext.getExternalContext().getResponse(); > response.setContentType(selectedContent.getContentType()); > > response.setHeader("Content-Disposition","attachment;filename=\"" > + selectedContent.getContentId() + "\""); > > response.setContentLength(selectedContent.getContentData().getData().len > gth); > > responseStream.write(selectedContent.getContentData().getData()); > > response.flushBuffer(); > } > catch (IOException exception) > { > // TODO Auto-generated catch block > exception.printStackTrace(); > } > > facesContext.responseComplete(); > > return null; > } > > > > On 10/21/05, CONNER, BRENDAN (SBCSI) <[EMAIL PROTECTED]> wrote: > > 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 > > >

