You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-user@portals.apache.org by Aaron Evans <aa...@gmail.com> on 2006/04/08 23:10:13 UTC

Re: Force downloading a file in JSF portlet

Raj,

A portlet cannot alter those response headers the way a servlet can.

I believe your options are to either use the file server component of
the pipeline (which to be honest I don't know much about) or you could
simply make the link a link to a servlet within your application,
thereby by-passing jetspeed.

HTH,
aaron

On 4/8/06, Raj Saini <ra...@gmail.com> wrote:
> Hi,
>
>
> I am building JSF based portlet for downloading a file using MyFaces JSF
> bridge.
> I do the following to make the file force download:
>
> 1) Set "content-disposition" header to contain the correct filename
> 2) Set "content-type" header to "application/octet-stream" or something
> more accurate if the information is present in attachment metadata
> 3) Dump the content using a ServletOutputStream
>
> When I click on the link to download the file, instead of throwing a
> dialog box for saving/opening the file, browser dumps the the binary
> contents on page. However, this works fine as standalone application.
>
> Is there something extra I need to do to force download file in
> Jetspeed? Am I missing something here?
>
> Regards,
>
> Raj
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org


Re: Force downloading a file in JSF portlet

Posted by Aaron Evans <aa...@gmail.com>.
I don't think you may do request forwarding from a portlet application
(but you can do redirects and includes).

So, instead of creating the download link via  a "command link" that
maps to an action listener that will handle the download, you use a
link that points to a servlet that will take the place of the action
listener for the download.  I know, it's not pretty, but it will work
and it's portable.

As Vlad has explained, you can simply output a link in your portlet's
rendered markup that is the URI to a servlet that is also a part of
your servlet/portlet web app.

So, to mimic Vlad's example, you put something like this in your
web.xml (where com.mycompany.servlet.MyDownloadServlet is the servlet
that will write the content to the output stream):

<web-app>
...
 <servlet>
   <servlet-name>documents</servlet-name>
   <servlet-class>com.mycompany.servlet.MyDownloadServlet</servlet-class>
   <load-on-startup>1</load-on-startup>
 </servlet>
...


 <servlet-mapping>
   <servlet-name>documents</servlet-name>
   <url-pattern>/documents/download.do</url-pattern>
 </servlet-mapping>
...
</web-app>

Then, if you output a link to /<web app
context>/documents/download.do, when a user clicks it, then the
content will be served by that servlet and you can then alter the
response headers and write binary content to the output stream from
within the servlet code.

The way you generate the actual link is irrelevant, you can use a JSF
tag (which I am not too familiar with), or you can simply write the
string directly (ie <%= myURIString  %>).

HTH,
aaron

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org


Re: Force downloading a file in JSF portlet

Posted by Raj Saini <ra...@gmail.com>.
Hi Aaron,


Can you tell me in little more details, how to give link to a servlet
in JSF? Currently I am using CommandLink component and I dont see a
way of giving direct link to servlet.

Regards,

Raj


On 4/9/06, Aaron Evans <aa...@gmail.com> wrote:
> Raj,
>
> A portlet cannot alter those response headers the way a servlet can.
>
> I believe your options are to either use the file server component of
> the pipeline (which to be honest I don't know much about) or you could
> simply make the link a link to a servlet within your application,
> thereby by-passing jetspeed.
>
> HTH,
> aaron
>
> On 4/8/06, Raj Saini <ra...@gmail.com> wrote:
> > Hi,
> >
> >
> > I am building JSF based portlet for downloading a file using MyFaces JSF
> > bridge.
> > I do the following to make the file force download:
> >
> > 1) Set "content-disposition" header to contain the correct filename
> > 2) Set "content-type" header to "application/octet-stream" or something
> > more accurate if the information is present in attachment metadata
> > 3) Dump the content using a ServletOutputStream
> >
> > When I click on the link to download the file, instead of throwing a
> > dialog box for saving/opening the file, browser dumps the the binary
> > contents on page. However, this works fine as standalone application.
> >
> > Is there something extra I need to do to force download file in
> > Jetspeed? Am I missing something here?
> >
> > Regards,
> >
> > Raj
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> > For additional commands, e-mail: jetspeed-user-help@portals.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org