incubator-adffaces-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "William Hoover" <whoo...@nemours.org>
Subject RE: Providing Files / Streams as download-link with trinidad?
Date Tue, 27 Mar 2007 11:55:19 GMT
Matthias,

I have been struggling with the same problem when streaming files for download. I have tried
the solution described below, but I still recieve an java.lang.IllegalStateException- even
when calling FacesContext.getCurrentInstance().responseComplete(). This also breaks all of
the links/buttons on the page.

-----Original Message-----
From: mwessendorf@gmail.com [mailto:mwessendorf@gmail.com]On Behalf Of
Matthias Wessendorf
Sent: Tuesday, March 27, 2007 4:48 AM
To: adffaces-user@incubator.apache.org
Subject: Re: Providing Files / Streams as download-link with trinidad?


Hello Jochen,

I've worked with Apache FOP for creating pdfs. iText or
JasperReports are also lib that help you on that task.

inside of your backing bean method (referenced by a commandLink or
cmdButton) you can do somthing like this:

public String pdf() {

  FacesContext ctx = FacesContext.getCurrentInstance();

  if(!ctx.getResponseComplete()) {


      HttpServletResponse response = (HttpServletResponse)
ctx.getExternalContext().getResponse();

      byte[] file = //do some FOP, or ... stuff;

      response.setContentType("application/pdf");
      response.setHeader("Content-Disposition", "inline;
filename=\"foo.pdf\"");
      response.setContentLength(file.length);

      OutputStream out = response.getOutputStream();
      out.write(file, 0, file.length);
      out.flush();
      out.close();

      ctx.responseComplete();

  return null;
 }


This will work in p(l)ain servlet or struts world too (expect of the
usage of jsf api (like FacesContext))

However, the *magic* here is the responseComplete()
<from_java_doc>
Signal the JavaServer Faces implementation that the HTTP response for
this request has already been generated (such as an HTTP redirect),
and that the request processing lifecycle should be terminated as soon
as the current phase is completed.
</from_java_doc>

and yes... it's getResponseComplete() instead of isResponseComplete()

HTH,
Matthias

On 3/27/07, Jochen Traunecker <madnecker@yahoo.com> wrote:
> Hello everybody,
>
> I'm just wondering if there is some Trinidad-specific / Faces-specific way to serve binary
downloads, like PDFs stored in a database. Or do I have to provide some link to a non managed
servlet?
>
> Thanks,
> Jochen
>
>
>
>
>
> ___________________________________________________________
> Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de
>


-- 
Matthias Wessendorf
http://tinyurl.com/fmywh

further stuff:
blog: http://jroller.com/page/mwessendorf
mail: mwessendorf-at-gmail-dot-com


Mime
View raw message