Frage

Ich möchte eine Datei mit AJAX in Wicket hochladen. Es scheint mir, dass Wicket nicht diese Funktion unterstützen. Ist es möglich?

War es hilfreich?

Lösung

Überprüfen Sie den Quellcode von den Wicket Beispiele für den Upload aus: http: //www.wicketstuff .org / wicket13 / upload / Einzel . Es hat Beispiele für Standard- und Ajax-Versionen.

Andere Tipps

Als ein Update auf eine alte Frage, wie es scheint es möglich ist, gerade jetzt:

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

Dieser Ansatz funktioniert gut für mich mit einem vollen Ajax Wicket App. Leider ist die Scala Syntax sollte aber leicht zurück auf Java-Syntax übertragbar:

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>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top