You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Stefan Renz <s....@efonds.com> on 2014/12/04 13:17:42 UTC

Download file and redirect in one go?

Hi,

after a form submission, I'd like to redirect the user to another page,
and stream a file to the browser (generated as a result of the form
submission).

How would I achieve this? I can do both single steps, but not both
together...

Thanks, bye,
Stefan


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Download file and redirect in one go?

Posted by Stefan Renz <s....@efonds.com>.
Thanks, Martin, I'll try to follow that route...

bye,
   Stefam

Martin Grigorov wrote:
> Hi,
> 
> Doing everything in the page with the form looks harder but maybe not
> impossible!
> 
> Here is an idea:
> 
> - use AjaxButton/AjaxSubmitLink/AjaxFormSubmitBehavior to submit the form
> - for the Ajax component/behavior override #updateAjaxAttributes() and set
> the flag that Wicket should not try to process the Ajax response
> (org.apache.wicket.ajax.attributes.AjaxRequestAttributes#setWicketAjaxResponse(false))
> - using the Ajax attributes you should setup onSuccess() JavaScript handler
> - the Ajax response should bring two urls, e.g. in simple JSON - one url to
> the download resource listener (use
> https://cwiki.apache.org/confluence/display/WICKET/AJAX+update+and+file+download+in+one+blow
> to see how to generate it) and a second url to the next page (use
> RequestCycle#urlFor(SecondPage.class, parameters) here)
> - the JS logic in the onSuccess handler should be something like:
> 
> function(attrs, jqXHR, data, textStatus) {
>   var downloadWindow = window.open(data.downloadUrl);
>   downloadWindow.onload(function()
> {document.top.location.href=data.redirectUrl;})
> }
> 
> I'm not sure whether it will work but it is worth trying!
> 
> 
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
> 
> On Thu, Dec 4, 2014 at 5:54 PM, Ernesto Reinaldo Barreiro <
> reiern70@gmail.com> wrote:
> 
>> You can also
>>
>> 1- mount a resource and serve the file from there.
>> 2- Once new page is loaded you do setTimeout(\"window.location.href='" +
>> url + "'\", 100); where url is the URL of the resource. This will trigger
>> download.
>>
>> On Thu, Dec 4, 2014 at 4:50 PM, Stefan Renz <s....@efonds.com> wrote:
>>
>>> Hi,
>>>
>>> how do I automatically trigger an AJAX request? Timer behavior?
>>>
>>> Any other ideas? I'd rather like to keep the download (resource
>>> generating code) on the page that contains the form. The page I want to
>>> redirect to has nothing to do with the resource...
>>>
>>> Thanks, bye
>>>    Stefan
>>>
>>> Ernesto Reinaldo Barreiro wrote:
>>>> After submit redirect  to the new page that automatically trigger an
>> AJAX
>>>> request and use
>>>>
>>>>
>> https://cwiki.apache.org/confluence/display/WICKET/AJAX+update+and+file+download+in+one+blow
>>>> On Thu, Dec 4, 2014 at 12:17 PM, Stefan Renz <s....@efonds.com>
>> wrote:
>>>>> Hi,
>>>>>
>>>>> after a form submission, I'd like to redirect the user to another
>> page,
>>>>> and stream a file to the browser (generated as a result of the form
>>>>> submission).
>>>>>
>>>>> How would I achieve this? I can do both single steps, but not both
>>>>> together...
>>>>>
>>>>> Thanks, bye,
>>>>> Stefan
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>
>>>>>
>>>>
>>> --
>>> im Auftrag der eFonds Solutions AG, +49-89-579494-3417
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>
>> --
>> Regards - Ernesto Reinaldo Barreiro
>>
> 

-- 
im Auftrag der eFonds Solutions AG, +49-89-579494-3417


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Download file and redirect in one go?

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

Doing everything in the page with the form looks harder but maybe not
impossible!

Here is an idea:

- use AjaxButton/AjaxSubmitLink/AjaxFormSubmitBehavior to submit the form
- for the Ajax component/behavior override #updateAjaxAttributes() and set
the flag that Wicket should not try to process the Ajax response
(org.apache.wicket.ajax.attributes.AjaxRequestAttributes#setWicketAjaxResponse(false))
- using the Ajax attributes you should setup onSuccess() JavaScript handler
- the Ajax response should bring two urls, e.g. in simple JSON - one url to
the download resource listener (use
https://cwiki.apache.org/confluence/display/WICKET/AJAX+update+and+file+download+in+one+blow
to see how to generate it) and a second url to the next page (use
RequestCycle#urlFor(SecondPage.class, parameters) here)
- the JS logic in the onSuccess handler should be something like:

function(attrs, jqXHR, data, textStatus) {
  var downloadWindow = window.open(data.downloadUrl);
  downloadWindow.onload(function()
{document.top.location.href=data.redirectUrl;})
}

I'm not sure whether it will work but it is worth trying!


Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Thu, Dec 4, 2014 at 5:54 PM, Ernesto Reinaldo Barreiro <
reiern70@gmail.com> wrote:

> You can also
>
> 1- mount a resource and serve the file from there.
> 2- Once new page is loaded you do setTimeout(\"window.location.href='" +
> url + "'\", 100); where url is the URL of the resource. This will trigger
> download.
>
> On Thu, Dec 4, 2014 at 4:50 PM, Stefan Renz <s....@efonds.com> wrote:
>
> > Hi,
> >
> > how do I automatically trigger an AJAX request? Timer behavior?
> >
> > Any other ideas? I'd rather like to keep the download (resource
> > generating code) on the page that contains the form. The page I want to
> > redirect to has nothing to do with the resource...
> >
> > Thanks, bye
> >    Stefan
> >
> > Ernesto Reinaldo Barreiro wrote:
> > > After submit redirect  to the new page that automatically trigger an
> AJAX
> > > request and use
> > >
> > >
> >
> https://cwiki.apache.org/confluence/display/WICKET/AJAX+update+and+file+download+in+one+blow
> > >
> > > On Thu, Dec 4, 2014 at 12:17 PM, Stefan Renz <s....@efonds.com>
> wrote:
> > >
> > >> Hi,
> > >>
> > >> after a form submission, I'd like to redirect the user to another
> page,
> > >> and stream a file to the browser (generated as a result of the form
> > >> submission).
> > >>
> > >> How would I achieve this? I can do both single steps, but not both
> > >> together...
> > >>
> > >> Thanks, bye,
> > >> Stefan
> > >>
> > >>
> > >> ---------------------------------------------------------------------
> > >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > >> For additional commands, e-mail: users-help@wicket.apache.org
> > >>
> > >>
> > >
> > >
> >
> > --
> > im Auftrag der eFonds Solutions AG, +49-89-579494-3417
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>
>
> --
> Regards - Ernesto Reinaldo Barreiro
>

Re: Download file and redirect in one go?

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
You can also

1- mount a resource and serve the file from there.
2- Once new page is loaded you do setTimeout(\"window.location.href='" +
url + "'\", 100); where url is the URL of the resource. This will trigger
download.

On Thu, Dec 4, 2014 at 4:50 PM, Stefan Renz <s....@efonds.com> wrote:

> Hi,
>
> how do I automatically trigger an AJAX request? Timer behavior?
>
> Any other ideas? I'd rather like to keep the download (resource
> generating code) on the page that contains the form. The page I want to
> redirect to has nothing to do with the resource...
>
> Thanks, bye
>    Stefan
>
> Ernesto Reinaldo Barreiro wrote:
> > After submit redirect  to the new page that automatically trigger an AJAX
> > request and use
> >
> >
> https://cwiki.apache.org/confluence/display/WICKET/AJAX+update+and+file+download+in+one+blow
> >
> > On Thu, Dec 4, 2014 at 12:17 PM, Stefan Renz <s....@efonds.com> wrote:
> >
> >> Hi,
> >>
> >> after a form submission, I'd like to redirect the user to another page,
> >> and stream a file to the browser (generated as a result of the form
> >> submission).
> >>
> >> How would I achieve this? I can do both single steps, but not both
> >> together...
> >>
> >> Thanks, bye,
> >> Stefan
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >>
> >
> >
>
> --
> im Auftrag der eFonds Solutions AG, +49-89-579494-3417
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Regards - Ernesto Reinaldo Barreiro

Re: Download file and redirect in one go?

Posted by Stefan Renz <s....@efonds.com>.
Hi,

how do I automatically trigger an AJAX request? Timer behavior?

Any other ideas? I'd rather like to keep the download (resource
generating code) on the page that contains the form. The page I want to
redirect to has nothing to do with the resource...

Thanks, bye
   Stefan

Ernesto Reinaldo Barreiro wrote:
> After submit redirect  to the new page that automatically trigger an AJAX
> request and use
> 
> https://cwiki.apache.org/confluence/display/WICKET/AJAX+update+and+file+download+in+one+blow
> 
> On Thu, Dec 4, 2014 at 12:17 PM, Stefan Renz <s....@efonds.com> wrote:
> 
>> Hi,
>>
>> after a form submission, I'd like to redirect the user to another page,
>> and stream a file to the browser (generated as a result of the form
>> submission).
>>
>> How would I achieve this? I can do both single steps, but not both
>> together...
>>
>> Thanks, bye,
>> Stefan
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
> 
> 

-- 
im Auftrag der eFonds Solutions AG, +49-89-579494-3417


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Download file and redirect in one go?

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
After submit redirect  to the new page that automatically trigger an AJAX
request and use

https://cwiki.apache.org/confluence/display/WICKET/AJAX+update+and+file+download+in+one+blow

On Thu, Dec 4, 2014 at 12:17 PM, Stefan Renz <s....@efonds.com> wrote:

> Hi,
>
> after a form submission, I'd like to redirect the user to another page,
> and stream a file to the browser (generated as a result of the form
> submission).
>
> How would I achieve this? I can do both single steps, but not both
> together...
>
> Thanks, bye,
> Stefan
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Regards - Ernesto Reinaldo Barreiro