-
Notifications
You must be signed in to change notification settings - Fork 296
Html5
The wicket-html5 module contains classes that give wicket support for using exciting new Html5 features like FileApi, Geolocation, <video>, <audio>.
Add this to your pom.xml:
<dependency>
<groupId>org.wicketstuff</groupId>
<artifactId>wicket-html5</artifactId>
<version>[some-version]</version>
</dependency>
This package contains support for the Html5 FileApi.
Gives limited access for javascript to read information (name, file size, type, last modified date) about the files choosen for a file upload field. Currently it is implemented in Chrome and Firefox but not in Internet Explorer and Opera.
This behavior can be added to FileUploadField-s to provide a convenient and fast size checking for users using FileApi supporting browsers. Using this has the benefit that the user does not have to upload the whole file data to receive an error about it exceeding the size limit. By default an ajax call is triggered when the user changes the value of the upload field (selects/deselects files). For browsers not implementing the FileApi this behavior does not change or break anything (so it is safe for IE users).
Usage is very simple (similar to an AjaxButton), just add it to the field and specify what should happen when validation passes or fails:
final FileUploadField uploadField = new FileUploadField("file");
// add our FileApi based size check, errors are reported trough a
// feedback panel
uploadField.add(new FileFieldSizeCheckBehavior() {
private static final long serialVersionUID = 7228537141239670625L;
@Override
protected void onSubmit(AjaxRequestTarget target, FileList fileList) {
target.add(feedback);
}
@Override
protected void onError(AjaxRequestTarget target, FileList fileList) {
target.add(feedback);
}
});
If you want to do something different than check for size you can subclass FileFieldChangeBehavior.
Wicket-html5 depends on wicket-core 1.5-RC3<= and Java6.
For more info see the javadoc of the classes. For a complete example see the "wicket-html5-examples" web application.