Which version of Wicket are you using? I've tested your code enabling
file upload but it worked fine with both version 1.5.8 and 6.0.0
class AddProductForm extends Form<Product> {
private FileUploadField photoField;
public AddProductForm(String id, CompoundPropertyModel<Product> model) {
super(id, model);
//setMultiPart(true);
//setMaxSize(Bytes.megabytes(1L));
TextField<String> nameField = new TextField<String>("name");
nameField.setRequired(true);
nameField.setLabel(Model.of("Name"));
nameField.add(StringValidator.lengthBetween(3, 255));
TextArea<String> descriptionField = new
TextArea<String>("description");
descriptionField.setRequired(false);
descriptionField.setLabel(Model.of("Description"));
descriptionField.add(StringValidator.maximumLength(8000));
//photoField = new FileUploadField("photo"); (photo is not
part of Product class)
add(nameField);
add(descriptionField);
//add(photoField);
}
@Override
protected void onSubmit() {
super.onSubmit();
info("Following product was added: " + getModelObject().getName());
new ExpressdrukBeanAccessFacade().saveProduct(getModelObject());
if (photoField != null) {
FileUpload fileUpload = photoField.getFileUpload();
if (fileUpload != null) {
Folder folder = new
Folder(System.getProperty("java.io.tmpdir"));
try {
folder.ensureExists();
} catch (IOException ex) {
error("Folder can't be created");
return;
}
File photo = new File(folder, fileUpload.getClientFileName());
if (photo.exists()) {
error("File with this photo already exists !");
return;
}
try {
fileUpload.writeTo(photo);
} catch (IOException ex) {
error("Can't write file with photo to folder");
return;
}
info(String.format("File %s was saved successfully !",
fileUpload.getClientFileName()));
}
} else {
error("Photo filed is null !");
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org