Ah image takes a DownloadHandler as a parameter :D nice have overseen this.
The name “DownloadHandler” is in this case a little bit confusing, because i font wont to download something, but when i think more about it, i download indeed something to the client. Anyway, it works ;) Thanks a lot
Any hint for optimization? The mime typ can be any image format, thats why i set it dynamic and not static
I would like to claim that pretty much always it is better to use the “lower level API”, where one writes to the outputstream instead. This is not just “how it really works” and keeping it analog to other frameworks, but also one gets rid of that helper method, things are slightly more efficient (no BAIS over the content needed) and it is easier for the developer when you move to the most optimal solution (you generate the PDF on the fly instead of pull a cached version from the database). In case of the ImageItem it would be something like:
ImageItem currentItem = imageItems.get(currentIndex);
imageDisplay.setSrc(download -> {
download.setFileName(currentItem.getFileName());
// mime type & content lenght in the same way if needed
download.getOutputStream().write(currentItem.getContent());
});
Although in above some of the examples are technically more in LOC, they are effectively the same, and thus I think using the same API for both dynamically generated content and somehow cached stuff would be easier for Vaadin users. Currently I only see people getting confused what happens with the new helpers, but please educate if I’m missing something why these “helpers” are relevant.