Reputation: 73
I have a Crud (From Vaadin Pro) and would like to use the upload component in BinderCrudEditor. The Upload component doesn't store a value (or rather the HasValue interface is missing), so I can't use the Binder. Is there any way to include it somehow without creating an extra button in Crud for file upload and then working with listeners?
Upvotes: 2
Views: 765
Reputation: 10643
The simplest way to do this is perhaps to use CustomField
of Vaadin framework. What you need to actually decide is the return type. Also setting the value of the field is a bit awkward use case depending how you have selected the return type. So thus take this more as pseudocode example.
public class UploadField extends CustomField<InputStream> {
InputStream is;
FileBuffer buffer = new FileBuffer();
public UploadField() {
Upload upload = new Upload(buffer);
upload.setAcceptedFileTypes("image/jpeg");
upload.setMaxFiles(1);
upload.addSucceededListener(event -> {
is = buffer.getInputStream();
});
add(upload);
}
public String getFileName() {
return buffer.getFileName();
}
@Override
protected InputStream generateModelValue() {
return is;
}
@Override
protected void setPresentationValue(InputStream newPresentationValue) {
}
}
Upvotes: 5