also with version 1.5.7 I couldn't reproduce your error. I get an error
because during form submission Wicket doesn't find field 'photo' of
class Product, but that's perfectly normal. The following is the code I
used for the test:
public class HomePage extends WebPage {
private static final long serialVersionUID = 1L;
private Product product = new Product();
public HomePage(PageParameters parameters) {
super(parameters);
Form<Product> form = new AddProductForm("form", new
CompoundPropertyModel<Product>(product));
FeedbackPanel feedback = new FeedbackPanel("feedback");
add(feedback);
add(form);
}
}
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");
add(nameField);
add(descriptionField);
add(photoField);
}
@Override
protected void onSubmit() {
super.onSubmit();
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 !");
}
}
}
class Product implements Serializable {
private int id;
private String name;
private String description;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]