Form uploadForm(final Form form) {
return new Form("uploadForm") {
@Override
protected void onSubmit() {
FileUpload upload = fileUploadField.getFileUpload();
if (upload == null) {
warn("No file selected.");
return;
}
ByteArrayOutputStream bout = new ByteArrayOutputStream();
try {
IOUtils.copy(upload.getInputStream(), bout);
setRawSLD(new InputStreamReader(new ByteArrayInputStream(bout.toByteArray())));
editor.setModelObject(rawSLD);
} catch (IOException e) {
throw new WicketRuntimeException(e);
}
// update the style object
StyleInfo s = (StyleInfo) form.getModelObject();
if (s.getName() == null || "".equals(s.getName().trim())) {
// set it
nameTextField.setModelValue(ResponseUtils.stripExtension(upload
.getClientFileName()));
nameTextField.modelChanged();
}
}
};