I have nearly the same problem:

I have the link of a sample file (pdf, doc or something else) in the database.
Now the user should have the possibility to open this file via a CommandButton 
or CommandLink

I'm not quite sure, how I can do this?
Thx for help

-----Ursprüngliche Nachricht-----
Von: Mike Kienenberger [mailto:[EMAIL PROTECTED]
Gesendet: Samstag, 22. Oktober 2005 03:00
An: MyFaces Discussion
Betreff: Re: FileDownload capability?


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
> >
>


______________________________________________________________________

This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
your system manager.

This footnote also confirms that this email message has been swept
for the presence of computer viruses.
______________________________________________________________________

Reply via email to