Just follow the wiki: that's why it was created ;-)

On Thu, Apr 10, 2014 at 12:01 PM, <[email protected]> wrote:

> So I have to add the AjaxDownload to my form which add my DownloadButton?
> Like this:
>
> AJAXDownload download = new AJAXDownload()
> {
>     @Override
>     protected IResourceStream getResourceStream()
>     {
>         return createResourceStream(item.getModelObject());
>     }
> };
>
> Form<SlaReportModel> reportForm = new
> Form<SlaReportModel>("reportForm",new
> CompoundPropertyModel<SlaReportModel>(new SlaReportModel()));
> reportForm.add(download);
> reportForm.add(new CustomDownloadButton("submit", reportForm, feedback,
> "SLA_Report"));
>
>
> Mit freundlichen Grüßen
> Christoph Manig
>
> -----Ursprüngliche Nachricht-----
> Von: Ernesto Reinaldo Barreiro [mailto:[email protected]]
> Gesendet: Donnerstag, 10. April 2014 11:53
> An: [email protected]
> Betreff: Re: Download excel-file
>
> You cannot stream a PDF back to client via AJAX. Have a look at.
>
>
> https://cwiki.apache.org/confluence/display/WICKET/AJAX+update+and+file+download+in+one+blow
>
>
> On Thu, Apr 10, 2014 at 11:47 AM, <[email protected]> wrote:
>
> > Hello,
> >
> > I want to download an excelfile, which will be created on the fly by
> > clicking on a button. So I have created my own downloadButton. The
> > excel-file will be created, it works fine but the download do not
> > work. I have started my application in development mode, but no
> > exception will be thrown. But in the wicket ajax panel I found this
> message: ERROR:
> > Wicket.Ajax.Call.failure: Error while parsing response: Could not find
> > root <ajax-response> element
> >
> > Here is the code of my button:
> >
> > public class CustomDownloadButton extends AjaxFallbackButton {
> >     private static final Logger log =
> > LoggerFactory.getLogger(CustomDownloadButton.class);
> >     private CSSFeedbackPanel feedback;
> >     private String filename;
> >
> >     public CustomDownloadButton(String id, Form<?> form,
> > CSSFeedbackPanel feedback, String filename) {
> >         super(id, form);
> >         this.feedback = feedback;
> >         this.filename = filename;
> >     }
> >
> >     @Override
> >     public void onSubmit(AjaxRequestTarget target, Form form) {
> >         target.add(feedback);
> >         SlaReportModel slaReportModel =
> > (SlaReportModel)form.getModelObject();
> >         if(!slaReportModel.isEmpty()){
> >
> >
> download(createFileForDownload(slaReportModel.getTxtDatumVon(),slaReportModel.getTxtDatumBis()));
> >         }else{
> >             error("Sie müssen den Zeitraum angeben!");
> >         }
> >
> >     }
> >
> >     private File createFileForDownload(Date beginDate, Date endDate) {
> >         log.debug("Creating file for download!");
> >         File tempFile = null;
> >         try
> >         {
> >             tempFile = File.createTempFile("SLA", ".xls");
> >
> >             InputStream data = new
> >
> ByteArrayInputStream(ConsoleDataHandlerImpl.getInstance().getReportAsByteStream(beginDate,endDate));
> >             Files.writeTo(tempFile, data);
> >
> >         } catch (Exception e) {
> >             log.debug(e.getStackTrace().toString());
> >         }
> >         log.debug("File " + tempFile.getName() + " was successfully
> > created!");
> >         return tempFile;
> >     }
> >
> >     private void download(final File fileForDownload) {
> >         log.debug("Preparing download file " +
> fileForDownload.getName());
> >         System.out.println(fileForDownload.toString());
> >         if (fileForDownload == null){
> >             throw new IllegalStateException(getClass().getName() + "
> > there is no file, file is null!");
> >         }
> >
> >         IResourceStream resourceStream = new FileResourceStream(new
> > org.apache.wicket.util.file.File(fileForDownload));
> >         getRequestCycle().scheduleRequestHandlerAfterCurrent(new
> > ResourceStreamRequestHandler(resourceStream) {
> >             @Override
> >             public void respond(IRequestCycle requestCycle) {
> >
> >                 super.respond(requestCycle);
> >                 //Files.remove(fileForDownload);
> >
> >             }
> >         }.setFileName(this.filename));
> >
> > //.setContentDisposition(ContentDisposition.ATTACHMENT)
> >
> > //.setCacheDuration(org.apache.wicket.util.time.Duration.NONE));
> >     }
> >
> >     @Override
> >     protected void onError(AjaxRequestTarget target, Form<?> form)
> >     {
> >         // repaint the feedback panel so errors are shown
> >         target.add(feedback);
> >     }
> > }
> >
> >
> > Mit freundlichen Grüßen
> > Christoph Manig
> >
> >
> >
> >
>
>
> --
> Regards - Ernesto Reinaldo Barreiro
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>


-- 
Regards - Ernesto Reinaldo Barreiro

Reply via email to