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()).getOutputStream();
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().length);
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
>