Upload linker
Utility class for Vaadin that allows the Vaadin Upload component to be triggered by any other component
Links any AbstractComponent to an Upload component. This means that upon a click on the linked component this click will be "forwarded" to the uploader and trigger its file selector window. Multiple uploaders can be successively linked to a single upload; multiple components can also be linked to a single uploader. Simply call link(AbstractComponent, Upload) for each component/uploader combination.
Known limitations:
- The linking is not permanent. If you reload a page you must reapply it.
- Both the component and the uploader must be added towards the view where you want to use them.
- Both the component and the uploader must be visible (i.e., don't use Component#setVisible(boolean) with false as this removes the component from the DOM.
- After the linking the upload component will be made invisible via CSS (style.display='none'). This may affect your layout! So best add the uploader at a convenient space - for instance at the bottom
- The component and the uploader must have their IDs set. See: Upload#setId(String), AbstractComponent#setId(String)
- These IDs must be unique.
- In case you build your UI lazily ensure that the components you want to link are present. This method waits an increasing amount of time (25ms, 50ms, 75ms, ...)
- for the components to be found and will time out after about 12s (30 attempts). (You can check successful/failed linkings via your browser's console.)
- Other registered ClickListeners will still fire for the source and target component.
Sample code
Upload upload = new Upload(); upload.setId("myupload"); upload.setReceiver( new Upload.Receiver() { @Override public OutputStream receiveUpload(String filename, String mimeType) { //your code here } } ); layout.addComponents(upload); Image img = new Image("cat", new ThemeResource("img/cat.gif")); img.setId("cat"); layout.addComponent(img); UploadLinker.link(img, upload);
Links
Compatibility
Was this helpful? Need more help?
Leave a comment or a question below. You can also join
the chat on Discord or
ask questions on StackOverflow.
Version
Initial release
- Released
- 2019-01-29
- Maturity
- TESTED
- License
- Apache License 2.0
Compatibility
- Framework
- Vaadin 8.0+
- Browser
- Browser Independent
Upload linker - Vaadin Add-on Directory
Utility class for Vaadin that allows the Vaadin Upload component to be triggered by any other componentLinks any AbstractComponent to an Upload component. This means that upon a click on the linked component this click will be "forwarded" to the uploader and trigger its file selector window. Multiple uploaders can be successively linked to a single upload; multiple components can also be linked to a single uploader. Simply call link(AbstractComponent, Upload) for each component/uploader combination.
Known limitations:
* The linking is not permanent. If you reload a page you must reapply it.
* Both the component and the uploader *must* be added towards the view where you want to use them.
* Both the component and the uploader *must* be visible (i.e., don't use Component#setVisible(boolean) with *false* as this removes the component from the DOM.
* After the linking the upload component will be made invisible via CSS (style.display='none'). This may affect your layout! So best add the uploader at a convenient space - for instance at the bottom
* The component and the uploader *must* have their IDs set. See: Upload#setId(String),
AbstractComponent#setId(String)
* These IDs *must* be unique.
* In case you build your UI lazily ensure that the components you want to link are present. This method waits an increasing amount of time (25ms, 50ms, 75ms, ...)
* for the components to be found and will time out after about 12s (30 attempts). (You can check successful/failed linkings via your browser's console.)
* Other registered ClickListeners will still fire for the source and target component.