Created
May 11, 2023 06:55
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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