You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Josh Chappelle <jc...@4redi.com> on 2012/03/21 18:53:12 UTC

Streaming a zip file then going back to previous BreadCrumbPanel

Hi,

I have a Wizard that is inside a BreadCrumbPanel. I have implemented a
method in the onCancel that goes back to the previous BreadCrumbPanel. This
is how it is implemented:

List<IBreadCrumbParticipant> participants =
crumbModel.allBreadCrumbParticipants();
crumbModel.setActive(participants.get(participants.size() - 2));

This works fine. The problem is in my onFinish. This wizard creates a zip
file that exports some documents from our system. The code for this is
below. I would like the onFinish to send the zip file back to the user and
then return to the previous BreadCrumbPanel. I'm not able to do that with
the code below. Does anyone have any ideas on how to do this?


ResourceStreamRequestHandler target = new ResourceStreamRequestHandler(new
AbstractResourceStreamWriter()
{
public void write(Response response)
{
try
{
ResponseOutputStream out = new ResponseOutputStream(response);
ZipOutputStream zip = new ZipOutputStream(out);
policyService.exportPolicies(zip, policyService.getPolicies());
zip.close();
}
catch(IOException e)
{
throw new RuntimeException("Failed to export all policies.", e);
}
}
 @Override
public String getContentType()
{
return "application/zip";
}
});
target.setFileName("All Policies.zip");

getRequestCycle().scheduleRequestHandlerAfterCurrent(target);
List<IBreadCrumbParticipant> participants =
crumbModel.allBreadCrumbParticipants();
crumbModel.setActive(participants.get(participants.size() - 2));


I'm using wicket 1.5.4 by the way.

Thanks,

Josh

Re: Streaming a zip file then going back to previous BreadCrumbPanel

Posted by jchappelle <jc...@4redi.com>.
Ahhh. I see what you are saying. I don't have a problem with the user seeing
the previous panel and then seeing the download prompt. I think I can get
the url for my IRequestHandler from the RequestCycle and then just generate
the javascript that goes back to the server and initiates the download.

Thanks a lot!

Josh

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Streaming-a-zip-file-then-going-back-to-previous-BreadCrumbPanel-tp4493168p4495811.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Streaming a zip file then going back to previous BreadCrumbPanel

Posted by Dan Retzlaff <dr...@gmail.com>.
Actually I meant to suggest that your response go ahead and render the
previous BreadcrumbPanel, and include JavaScript that HTTP redirects the
user to your resource (essentially "window.location=<resource URL>"). The
UX is different than you describe since the user will be looking at the
previous panel during the download.

The problem is that without a solution like AJAX polling, AFAIK there's no
way to monitor download progress from your webpage, and hence trigger the
redirect after it completes. The download happens in total isolation from
your page's JavaScript environment.

Dan

On Wed, Mar 21, 2012 at 5:42 PM, jchappelle <jc...@4redi.com> wrote:

> When you say "Can you initiate the download *after* your redirect?" I'm
> guessing you mean this:
>
> List<IBreadCrumbParticipant> participants =
> crumbModel.allBreadCrumbParticipants();
> crumbModel.setActive(participants.get(participants.size() - 2));
> getRequestCycle().scheduleRequestHandlerAfterCurrent(target);
>
> I have tried this and it doesn't work either.
>
> The ajax idea is a good idea although I would use that as a last resort. I
> was hoping that their was a cleaner way that doesn't generate a lot of
> traffic to the server. I wonder if I could create an IRequestHandler that
> holds a reference to two other IRequestHandlers. The first being the
> streaming zip file, the second being one that updates the breadcrumb model
> and refreshes via ajax. I don't know exactly how to implement that second
> one though.
>
> Thanks for the help.
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Streaming-a-zip-file-then-going-back-to-previous-BreadCrumbPanel-tp4493168p4494225.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Streaming a zip file then going back to previous BreadCrumbPanel

Posted by jchappelle <jc...@4redi.com>.
When you say "Can you initiate the download *after* your redirect?" I'm
guessing you mean this:

List<IBreadCrumbParticipant> participants =
crumbModel.allBreadCrumbParticipants(); 
crumbModel.setActive(participants.get(participants.size() - 2)); 
getRequestCycle().scheduleRequestHandlerAfterCurrent(target); 

I have tried this and it doesn't work either. 

The ajax idea is a good idea although I would use that as a last resort. I
was hoping that their was a cleaner way that doesn't generate a lot of
traffic to the server. I wonder if I could create an IRequestHandler that
holds a reference to two other IRequestHandlers. The first being the
streaming zip file, the second being one that updates the breadcrumb model
and refreshes via ajax. I don't know exactly how to implement that second
one though.

Thanks for the help.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Streaming-a-zip-file-then-going-back-to-previous-BreadCrumbPanel-tp4493168p4494225.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Streaming a zip file then going back to previous BreadCrumbPanel

Posted by Dan Retzlaff <dr...@gmail.com>.
Can you initiate the download *after* your redirect? Otherwise I think you
can have your resource set a session variable when the upload is complete,
and poll for that with AJAX.

Dan

On Wed, Mar 21, 2012 at 10:53 AM, Josh Chappelle <jc...@4redi.com>wrote:

> Hi,
>
> I have a Wizard that is inside a BreadCrumbPanel. I have implemented a
> method in the onCancel that goes back to the previous BreadCrumbPanel. This
> is how it is implemented:
>
> List<IBreadCrumbParticipant> participants =
> crumbModel.allBreadCrumbParticipants();
> crumbModel.setActive(participants.get(participants.size() - 2));
>
> This works fine. The problem is in my onFinish. This wizard creates a zip
> file that exports some documents from our system. The code for this is
> below. I would like the onFinish to send the zip file back to the user and
> then return to the previous BreadCrumbPanel. I'm not able to do that with
> the code below. Does anyone have any ideas on how to do this?
>
>
> ResourceStreamRequestHandler target = new ResourceStreamRequestHandler(new
> AbstractResourceStreamWriter()
> {
> public void write(Response response)
> {
> try
> {
> ResponseOutputStream out = new ResponseOutputStream(response);
> ZipOutputStream zip = new ZipOutputStream(out);
> policyService.exportPolicies(zip, policyService.getPolicies());
> zip.close();
> }
> catch(IOException e)
> {
> throw new RuntimeException("Failed to export all policies.", e);
> }
> }
>  @Override
> public String getContentType()
> {
> return "application/zip";
> }
> });
> target.setFileName("All Policies.zip");
>
> getRequestCycle().scheduleRequestHandlerAfterCurrent(target);
> List<IBreadCrumbParticipant> participants =
> crumbModel.allBreadCrumbParticipants();
> crumbModel.setActive(participants.get(participants.size() - 2));
>
>
> I'm using wicket 1.5.4 by the way.
>
> Thanks,
>
> Josh
>