Re: Ajax file download - Invalid XML
It should be the AJAX part that fails for some reason... If you put a break point on writeDownload you might see that no download request is produced. The trick work as follows. Please, try to provide a quick start or provide more info because I do not see how we could otherwise help you. On Tue, Jun 18, 2013 at 3:14 PM, René Hartwig rene.hart...@befine-solutions.com 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 ListTransferModel 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); 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: *rene.hart...@befine-solutions.com* 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/cryptsharehttp://www.linkedin.com/company/befine-solutions/products Amtsgericht Freiburg HRB 6144 Vorstand Mark Forrest, Dominik Lehr Aufsichtsratsvorsitzender Edgar Fehrenbacher -- Regards - Ernesto Reinaldo Barreiro
Re: Ajax file download - Invalid XML
Hi, On Tue, Jun 18, 2013 at 2:14 PM, René Hartwig rene.hart...@befine-solutions.com 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 ListTransferModel 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: *rene.hart...@befine-solutions.com* 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/cryptsharehttp://www.linkedin.com/company/befine-solutions/products Amtsgericht Freiburg HRB 6144 Vorstand Mark Forrest, Dominik Lehr Aufsichtsratsvorsitzender Edgar Fehrenbacher
Re: Ajax file download - Invalid XML
Well spotted.. and I guess the wrong XML error is because you are returning CSV instead of wicket AJAX XML. On Tue, Jun 18, 2013 at 3:26 PM, Martin Grigorov mgrigo...@apache.orgwrote: Hi, On Tue, Jun 18, 2013 at 2:14 PM, René Hartwig rene.hart...@befine-solutions.com 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 ListTransferModel 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: *rene.hart...@befine-solutions.com* 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/cryptsharehttp://www.linkedin.com/company/befine-solutions/products Amtsgericht Freiburg HRB 6144 Vorstand Mark Forrest, Dominik Lehr Aufsichtsratsvorsitzender Edgar Fehrenbacher -- Regards - Ernesto Reinaldo Barreiro
Re: Ajax file download - Invalid XML
Great, thanks - that was it Best regards, Ren Ren Hartwig Senior Developer Befine Solutions AG - The Cryptshare Company Bebelstrae 17 79108 Freiburg Germany Tel: +49 (0) 761 38913 0 Fax: +49 (0) 761 38913 115 E-Mail: rene.hart...@befine-solutions.com Internet: http://www.cryptshare.com = Your attachments are too large or too confidential for e-mail? Get to know Cryptshare! http://www.cryptshare.com = Amtsgericht Freiburg HRB 6144 Vorstand Mark Forrest, Dominik Lehr Aufsichtsratsvorsitzender Edgar Fehrenbacher Am 18.06.2013 13:32, schrieb Ernesto Reinaldo Barreiro: Well spotted.. and I guess the wrong XML error is because you are returning CSV instead of wicket AJAX XML. On Tue, Jun 18, 2013 at 3:26 PM, Martin Grigorov mgrigo...@apache.orgwrote: Hi, On Tue, Jun 18, 2013 at 2:14 PM, Ren Hartwig rene.hart...@befine-solutions.com 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 ListTransferModel 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=''\", 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* Bebelstrae 17 79108 Freiburg Germany Tel: +49 (0) 761 38913 0 Fax: +49 (0) 761 38913 115 E-Mail: *rene.hart...@befine-solutions.com* 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/cryptsharehttp://www.linkedin.com/company/befine-solutions/products Amtsgericht Freiburg HRB 6144 Vorstand Mark Forrest, Dominik Lehr Aufsichtsratsvorsitzender Edgar Fehrenbacher
Re: ajax file download...
Hi, On Fri, Oct 12, 2012 at 10:35 AM, mlabs mlabs@gmail.com wrote: So what I'm trying to do must surely be a common thing... yet so far I have had no luck getting it to work. I'm generating big PDF's on the server .. and in the browser I have a link that should initiate that generation and bring up a file 'save-as' dialog when the PDF is ready to be downloaded. While the generation phase is going on, I want to use jQuery.blockUI to stop the user from doing anything else in the app. 1-AJAX start PDF generation, on a different thread and retunr script to block UI, plus AJAX timer that will poll the server for PDF generation status. 2-Once PDF generation is finished, AJAX timer will unblock the UI and trigger AJAX download (and disable timer). -- Regards - Ernesto Reinaldo Barreiro Antilia Soft http://antiliasoft.com
Re: ajax file download...
you could even display a progress bar indicator so that your users are aware of how much it is left. On Fri, Oct 12, 2012 at 10:46 AM, Ernesto Reinaldo Barreiro reier...@gmail.com wrote: Hi, On Fri, Oct 12, 2012 at 10:35 AM, mlabs mlabs@gmail.com wrote: So what I'm trying to do must surely be a common thing... yet so far I have had no luck getting it to work. I'm generating big PDF's on the server .. and in the browser I have a link that should initiate that generation and bring up a file 'save-as' dialog when the PDF is ready to be downloaded. While the generation phase is going on, I want to use jQuery.blockUI to stop the user from doing anything else in the app. 1-AJAX start PDF generation, on a different thread and retunr script to block UI, plus AJAX timer that will poll the server for PDF generation status. 2-Once PDF generation is finished, AJAX timer will unblock the UI and trigger AJAX download (and disable timer). -- Regards - Ernesto Reinaldo Barreiro Antilia Soft http://antiliasoft.com -- Regards - Ernesto Reinaldo Barreiro Antilia Soft http://antiliasoft.com
Re: ajax file download...
hmm.. no .. sounds too complicated ... I don't want to get into spawning threads and polling .. In jQuery you can use $.ajax({url:'my-pdf resource-url',async:false,success...,error...}) and wire blockUI into the success/error handlers.. that worked great except the save-as dialog didn't come up - even though in my PDFSharedResource I was setting content-disposition to attachment... It seems to me that this 'synchronous' flag should be exposed in the wicket javascript somehow... But I haven't found it yet... only just started digging into this code... -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/ajax-file-download-tp4652911p4652915.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: ajax file download...
I know, but the idea of the user being able to click around the web page and possibly navigate to other areas of the app... and then minutes later the save-as dialog suddenly pops up .. seems to me to be potentially confusing... which is why I like blockUI ... it lets them know that as soon as they click the download link .. something is happening... -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/ajax-file-download-tp4652911p4652917.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: ajax file download...
The way I did it - I created a panel to be used by all reports. It uses IndicatingAjaxButton for Generate Report button which starts report generation in thread and adds AjaxSelfUpdating behaviour to the button panel. Once generation is finished, previously invisible Download Report button is enabled, which uses standard non-ajax DownloadLink to allow user to Download report. On 10/12/2012 12:19 PM, mlabs wrote: I know, but the idea of the user being able to click around the web page and possibly navigate to other areas of the app... and then minutes later the save-as dialog suddenly pops up .. seems to me to be potentially confusing... which is why I like blockUI ... it lets them know that as soon as they click the download link .. something is happening... -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/ajax-file-download-tp4652911p4652917.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: ajax file download...
ok i like the idea of enabling the download button upon completion of generation - I will have a go at doing something similar. But it seems to me that if there was a way to switch the ajax call to be synchronous 'on the fly' then there would be no need for polling with ajax timers (selfupdaingbehaviors) .. -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/ajax-file-download-tp4652911p4652928.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Ajax File Download with Form Process and Result Refresh
A regular form and an ajaxbutton should get you a long way. Assuming you have a feedbackpanel on your page. The onSubmit of your button should do something like: onSubmit(AjaxRequestTarget target) { //do calculation target.addComponent(getForm()); //somehow create and or upload pdf } onError(AjaxRequestTarget target) { //refresh feedback to show feedback messages target.add(feedbackpanel); } Now if someone else can explain the best way to serve a file from or after an ajax call. I think you have to use a regular request for that but who knows :) Maurice On Nov 22, 2007 4:18 PM, Francisco Diaz Trepat - gmail [EMAIL PROTECTED] wrote: Hi I have a forms that performs a calculation and shows the result, all done by an ajax form. I have an ajax link that has to return a PDF, but also refresh the results or execute the ajax form submit. Also if the form proces fails for a validation (eg. empty field) then I should show the validation messages in my feedback panel, and do not process de pdf for download. Anyone? thanks, f(t) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]