stefanuebe / vaadin-lazy-download-button Goto Github PK
View Code? Open in Web Editor NEWA component that allows lazy instantiation of download content.
Home Page: https://vaadin.com/directory/component/lazy-download-button
A component that allows lazy instantiation of download content.
Home Page: https://vaadin.com/directory/component/lazy-download-button
Hello.
Download button working super great when you set filename callback and inputstream callback and constructor.
But when i set filename and inputstream callback after the button was created, the download does not occur.
Example:
private final LazyDownloadButton downloadButton = new LazyDownloadButton(VaadinIcon.FILE_ZIP.create());
downloadButton.setFileNameCallback(() -> filename);
downloadButton.setInputStreamCallback(() -> new ByteArrayInputStream(byte array content));
Reason: looks like the constructor with only ICON does not add click listener for downloading
Update2 ():
1)
private LazyDownloadButton downloadButton = new LazyDownloadButton(VaadinIcon.FILE_ZIP.create(), null, null);
downloadButton.setFileNameCallback(() -> filename);
downloadButton.setInputStreamCallback(() -> new ByteArrayInputStream(byte array content));
Error:
java.lang.NullPointerException: File name callback must not be null
at java.util.Objects.requireNonNull(Objects.java:233) ~[?:?]
at org.vaadin.stefan.LazyDownloadButton.lambda$null$3(LazyDownloadButton.java:100) ~[lazy-download-button-1.0.0.jar:1.0.0]
Vaadin 23.2.3, 23.1.10
Java 17
If createInputStream
fails, it's not possible to intercept the exception and handle it.
Moreover, if setDisableOnClick
is set, the button will remain disabled (because no DownloadStartsEvent
will occur).
As a workaround, one need to write error handling logic inside of the InputStreamFactory
:
btnDownload = new LazyDownloadButton("Download",
() -> "foo.pdf",
() -> {
try {
return new ByteArrayInputStream(generateFile());
} catch (RuntimeException e) {
btnDownload.getUI().ifPresent(ui->ui.access(()->{
// restore normal state, so that the user can download the content again
btnDownload.setText("Download");
btnDownload.setEnabled(true);
Notification.show("Download failed").addThemeVariants(NotificationVariant.LUMO_ERROR);
}));
throw e;
}
});
Hi Stefan,
Is this component still being maintained? I cannot get either the demo at https://stefan.app.fi/lazy-download-button-demo/ to work (only the eager button works) and the integration in my application also does not work. Sometimes there is after some minutes a browser download popup saying there was an error downloading but thats it.
Thx for checking.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.