You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Raghu Yegavakota <ra...@gmail.com> on 2009/06/28 04:00:42 UTC
Returning a file attachment and a page together in a request
I am a newbie to Tapestry and have a question: I have a downloads page that
displays a list of files to the user. When the user clicks on any file link
I need to do one of two things:
1) If the user is logged in, I need to send the selected file as an
attachment to the browser
2) If the user is not logged in, I need to display the Login page. One the
user is successfully logged in, I need to display the downloads page and
also send the selected file as an attachment.
I am able to do (1) using StreamResponse but not sure how to solve (2)- send
a Page response back and a file as an attachment.
Any help is greatly appreciated.
Thanks,
Raghu.
Re: Returning a file attachment and a page together in a request
Posted by Geoffrey Wiseman <ge...@gmail.com>.
On Sun, Jun 28, 2009 at 12:08 AM, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:
> I am able to do (1) using StreamResponse but not sure how to solve (2)-
>> send a Page response back and a file as an attachment.
>>
>
>
> To redirect the user to a page (Login, for example), just return a page
> instance (got through @InjectPage) or the page class instance (Login.class)
> in the onActivate() method instead of the StreamResponse.
>
> As far as I know, you can't return a page and an attachment in the same
> request. Using Javascript (window.location = "...";) in the returned page,
> you can instruct the user's browser to make another request (in this case, a
> file as an attachment).
>
The typical approach is to return a page that either uses Javascript or a
Meta redirect to download the file, and include in the page a link that
allows the user to click to do the download if the other approaches fail.
Look at lots of popular download sites to get ideas -- anywhere where you
get a page like, "Your download should begin shortly; please _click here_ to
download if your download does not start."
- Geoffrey
--
Geoffrey Wiseman
http://www.geoffreywiseman.ca/
Re: Returning a file attachment and a page together in a request
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Sat, 27 Jun 2009 23:00:42 -0300, Raghu Yegavakota
<ra...@gmail.com> escreveu:
> I am a newbie to Tapestry and have a question:
Welcome! :)
> I am able to do (1) using StreamResponse but not sure how to solve (2)-
> send a Page response back and a file as an attachment.
To redirect the user to a page (Login, for example), just return a page
instance (got through @InjectPage) or the page class instance
(Login.class) in the onActivate() method instead of the StreamResponse.
As far as I know, you can't return a page and an attachment in the same
request. Using Javascript (window.location = "...";) in the returned page,
you can instruct the user's browser to make another request (in this case,
a file as an attachment).
--
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org