Этот подход работает для меня с полным приложением Ajax Wicket.
Извините, это синтаксис Scala, но его легко перенести обратно в синтаксис Java:
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>