Skip to content

Instantly share code, notes, and snippets.

@TatuLund
Created May 11, 2023 06:55
Show Gist options
  • Select an option

  • Save TatuLund/cefc227744402de815d520a3f69b8ebd to your computer and use it in GitHub Desktop.

Select an option

Save TatuLund/cefc227744402de815d520a3f69b8ebd to your computer and use it in GitHub Desktop.
A simple example of UploadField, custom field wrapping Upload component with HasValue and field component behavior for Vaadin 23/24.
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) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment