Search code examples
ajaxfile-uploadwicketnested-formspreview

Wicket file upload with preview


I am using wicket 1.7 and I would like to implement a file uploading cmponent (upload an image) with preview. I searched and read severals solutions into the Web but I do not understand well how to do it.

Is it mandatory to submit the form to obtain the preview ? And is it possible to submit only the file upload form and not the entire form ?

Is it possible to submit the form without adding a preview button and add simply an Ajax behavior on file upload ?

Thanks for any help. I am pretty new into the wicket world.


Solution

  • For file preview you don't need to upload the file to the server. This could be done with JavaScript.

    Wicket-Bootstrap provides integration with JavaScript widget that provides this functionality:

    demo: http://coding.teliclab.info/wicket-7.x/extensions/BootstrapFileInput

    JS widget: https://github.com/kartik-v/bootstrap-fileinput

    Wicket code: https://github.com/l0rdn1kk0n/wicket-bootstrap/tree/wicket-7.x/bootstrap-extensions/src/main/java/de/agilecoders/wicket/extensions/markup/html/bootstrap/form/fileinput

    Wicket example code: https://github.com/l0rdn1kk0n/wicket-bootstrap/blob/wicket-7.x/bootstrap-samples/src/main/java/de/agilecoders/wicket/samples/pages/ExtensionsBootstrapFileInputPage.java