Upload an AJAX file using Wicket

I want to upload a file using AJAX in Wicket. It seems to me that Wicket does not support this feature. Is it possible?

+4
source share
3 answers

Check out the source code from the Wicket examples for download: http://www.wicketstuff.org/wicket13/upload/single . It has examples for both standard and ajax versions.

+1
source

As updating an old question, it seems like this is possible right now:

http://www.wicket-library.com/wicket-examples/ajax/upload

+1
source

This approach works for me with the full Ajax application. Unfortunately, this is Scala syntax, but it is easy to port it back to Java syntax:

import java.io.File import org.apache.wicket.markup.html.form.upload.FileUploadField import org.apache.wicket.markup.html.form.Form import org.apache.wicket.markup.html.WebPage import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink import org.apache.wicket.ajax.AjaxRequestTarget class TestPage extends WebPage { val uploadForm = new Form("form") val fileField = new FileUploadField("file") uploadForm.add(fileField) add(form) add(new AjaxSubmitLink("submit", uploadForm) { def onSubmit(target: AjaxRequestTarget, form: Form[_]) { val upload = fileField.getFileUpload if (upload != null) { val file: File = upload.writeToTempFile } } }) } 

HTML:

 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd"> <body> <form wicket:id="form"> <input wicket:id="file" type="file"/> </form> <button wicket:id="submit">Upload</button> </body> </html> 
0
source

All Articles