我想在Wicket中使用AJAX上传文件。在我看来,Wicket不支持此功能。有可能吗?
答案 0 :(得分:1)
查看上传的Wicket示例中的源代码:http://www.wicketstuff.org/wicket13/upload/single。它有标准和ajax版本的示例。
答案 1 :(得分:1)
作为对旧问题的更新,现在似乎有可能:
答案 2 :(得分:0)
这种方法适用于我使用完整的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>