Hi,

On Tue, Jun 18, 2013 at 2:14 PM, René Hartwig <
[email protected]> wrote:

>  Hi,
>
> I'm using Wicket 6.7.0 with an embedded Jetty and implemented a file
> download mechanism as suggested here:
>
> https://cwiki.apache.org/confluence/display/WICKET/AJAX+update+and+file+download+in+one+blow
>
> My implementation is slighlty different from the suggested one, but still
> I think it is pretty much the same:
> private void writeDownload(final List<TransferModel> transfers) {
>         String fileName = UrlEncoder.QUERY_INSTANCE.encode("logExport-" +
> CalendarTool.format(beginDate) + "-" + CalendarTool.format(endDate)
>                 + ".csv", getRequest().getCharset());
>         IResourceStream resourceStream = new
> AbstractResourceStreamWriter() {
>
>             @Override
>             public void write(OutputStream output) throws IOException {
>                 BHLogExport.writeCSVLog(transfers, output, getLocalizer(),
> Session.get().getLocale(), LogExportPanel.this);
>             }
>
>             @Override
>             public String getContentType() {
>                 return "text/csv";
>             }
>         };
>         ResourceStreamRequestHandler resource = new
> ResourceStreamRequestHandler(resourceStream, fileName);
>         resource.setContentDisposition(ContentDisposition.ATTACHMENT);
>         resource.setCacheDuration(Duration.NONE);
>         // resource.setFileName(fileName);
>         getRequestCycle().scheduleRequestHandlerAfterCurrent(resource);
>

With the line above you are scheduling a request handler after the Ajax one
(AjaxRequestTarget), so you write directly the binary data in the Ajax
response.
This won't work.
Follow the wiki more closely. It does: target.appendJavaScript(
"setTimeout(\"window.location.href='" + url + "'\", 100);");
I.e. it makes a new request to load the binary.


>          try {
>             resourceStream.close();
>         } catch (IOException e) {
>             throw new CryptshareRuntimeException("An error occured while
> trying to write the csv file to the output stream.", e);
>         }
>     }
>
> I am using a custom Button wrapping an AjaxButton. Except from that, there
> is no difference, but I still keep getting an error message instead of
> the file download dialog.
> Do you have any suggestions what I might be doing wrong?
>
> Thanks and best regards,
> René Hartwig
> --
>
> René Hartwig
> Senior Developer
>
> *Befine Solutions AG - The Cryptshare Company*
> Bebelstraße 17
> 79108 Freiburg
> Germany
>
> Tel: +49 (0) 761 38913 0
> Fax: +49 (0) 761 38913 115
>
> E-Mail: *[email protected]*
> Internet: http://www.cryptshare.com
>
> =========================================================================
>
> Your attachments are too large or too confidential for e-mail?
> Get to know Cryptshare!
>
> http://www.cryptshare.com
>
> =========================================================================
>
>  
> <http://www.facebook.com/cryptshare><http://www.linkedin.com/company/befine-solutions/products>
>
> Amtsgericht Freiburg HRB 6144
> Vorstand Mark Forrest, Dominik Lehr
> Aufsichtsratsvorsitzender Edgar Fehrenbacher
>
>
>
>

Reply via email to