use of org.apache.wicket.markup.html.form.upload.FileUploadField in project projectforge by micromata.
the class SetupImportForm method init.
@Override
@SuppressWarnings("serial")
protected void init() {
FeedbackPanel feedbackPanel = createFeedbackPanel();
feedbackPanel.setOutputMarkupId(true);
add(feedbackPanel);
this.setOutputMarkupId(true);
// set max size
Bytes maxSize = Bytes.valueOf(configurationService.getMaxFileSizeXmlDumpImport());
this.setMaxSize(maxSize);
this.setMultiPart(true);
final GridBuilder gridBuilder = newGridBuilder(this, "flowform");
gridBuilder.newFormHeading(getString("import"));
{
// Upload dump file
final FieldsetPanel fs = gridBuilder.newFieldset(getString("administration.setup.dumpFile"));
fileUploadField = new FileUploadField(FileUploadPanel.WICKET_ID);
fs.add(new FileUploadPanel(fs.newChildId(), fileUploadField));
}
final RepeatingView actionButtons = new RepeatingView("buttons");
add(actionButtons);
{
final Button importButton = new Button(SingleButtonPanel.WICKET_ID, new Model<String>("import")) {
@Override
public final void onSubmit() {
csrfTokenHandler.onSubmit();
parentPage.upload();
}
};
final SingleButtonPanel importButtonPanel = new SingleButtonPanel(actionButtons.newChildId(), importButton, getString("import"), SingleButtonPanel.DEFAULT_SUBMIT);
actionButtons.add(importButtonPanel);
}
this.fileUploadField.add(new FileFieldSizeCheckBehavior() {
@Override
protected void onSubmit(final AjaxRequestTarget target, final FileList fileList) {
if (fileList.getNumOfFiles() == 1) {
if (false == (fileList.get(0).getName().endsWith(".xml.gz") || fileList.get(0).getName().endsWith(".xml")))
SetupImportForm.this.addError("common.uploadpanel.filewrongtype", ".xml; .xml.gz");
}
// return form to remove errors
target.add(feedbackPanel);
}
@Override
protected void addErrorMsg(AjaxRequestTarget target, FileList fileList) {
SetupImportForm.this.addError("common.uploadpanel.filetolarge", NumberHelper.formatBytes(maxSize.bytes()));
}
@Override
protected void onError(final AjaxRequestTarget target, final FileList fileList) {
// clear input field to avoid uploading the image
SetupImportForm.this.fileUploadField.clearInput();
// return form
target.add(SetupImportForm.this);
}
});
}
Aggregations