Hi,

Have a look at https://cwiki.apache.org/WICKET/ajax-update-and-file-download-in-one-blow.html and try to make it work in wicket 6 (should be easy).

This allows you to do ajax updates (e.g. refresh the form) and then redirect the browser to the file.

Met vriendelijke groet,
Kind regards,

Bas Gooren

Op 22-11-2012 12:51, schreef juhar:
Hi,

I have a page with a form on it. After the user has submitted the form
successfully (all the fields have validated ok), the server creates a
report-file based on the form values. The file is not created as physical
file on the server, but it is given as download to the user.

Now, if the user first fills the form incorrectly, there are validator
feedback messages shown. If the user then submits the form with correct
values, the problem is that previous feedback error messages are not
cleared. I can't also create a new feedback message saying something like
"The report was created successfully." The file download response prevents
any updating of the current page.

I tried submitting the form with ajax using AjaxButton, and was able to
clear the feedback messages, but unfortunately it would not work on IE8...
IE8 will warn you about the file with a pop-up, and after that the download
will just disappear. Also any of my attempts to manually clear the feedback
messages have failed.

What would be correct way of creating this? I'm using Wicket6. This is the
code I'm using currently (relevant bits only):

// In the Panel-constructor
form.add(new Button("createreportbutton") {
     @Override
     public void onSubmit() {
         createReport();
     }
});

// Generates the report, and response
private void createReport() {
     // Generate report with something like:
     reportCommand.generateReport(formValues);
     final byte[] reportData  = reportCommand.getReportData();
     final String contentType = reportCommand.getContentType();
     final String contentDisposition = reportCommand.getContentDisposition();

     // Give the report as download
     getRequestCycle().scheduleRequestHandlerAfterCurrent( new
IRequestHandler() {
         @Override
         public void detach(IRequestCycle reqCycle) {
         }

         @Override
         public void respond(IRequestCycle reqCycle) {
             WebResponse response = (WebResponse)reqCycle.getResponse();
             HttpServletResponse res =
(HttpServletResponse)response.getContainerResponse();
             res.setContentType(contentType);
             res.setHeader("Content-Disposition", contentDisposition);
             try {
                 res.getOutputStream().write(reportData);
             } catch (IOException ex) {
                 ApplicationLogger.error("Error writing report to HTTP
response", ex);
             }

         }
     });
}

Thanks,
Juha



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/File-download-through-form-submit-feedback-messages-tp4654087.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


Reply via email to