Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
BrowserWindowOpener with Button click event
Hi,
I am using Vaadin 7.6.5
Trying to open a BrowserWindowOpener as Popup when button is clicked with following code
Button button = new Button("Open");
BrowserWindowOpener opener = new BrowserWindowOpener(MyUI.class);
opener.setFeatures("height=700,width=600");
opener.setResource(new FileResource(new File("G:/New folder/test1470048449513.pdf")));
opener.setWindowName("PDF");
opener.extend(button);
it works fine for me , i need to open the BrowserWindowOpener based on some condision(ie i need to do two things check the file first and open BrowserWindowOpener ) when button is clecked so how can i do this code inside buttopn click listener.
Thanks
Nagaraj RC
Hi,
if you extend a Button with BrowserWindowOpener then a click handler will be added on the client side
so new window will be opened before your server side click listener is invoked.
If your need is to have a dynamic content generated on button click you can either implement a custom StreamSource and give it to a StreamResource or even extend StreamResource and override getStream or getStreamSource;
then you can initialize your BrowserWindowOpener with this StreamResource.
There are a lot of post regarding this argument on the forum.
Instead if you want to have your listener code inovked before window open take a look at this post ;
in this solution the click listener on client side does nothing and the window is opened at the end of the request generated by clicking the button, but this requires a widgetset recompilation.
HTH
Marco
Hello!
I'm here to tell that the below code, using button ClickListener event and setResource from BrowserWindowOpener worked fine for me:
final BrowserWindowOpener browserWindowOpener = new BrowserWindowOpener(resource);
downloadButton.addClickListener(listener -> {
StreamSource newSource = getStreamSource(simulationStockComboBoxFilter, defaultValue); //my custom StreamSource getter
StreamResource newResource = new StreamResource(newSource,
fileNameBeginning + formatter.format(LocalDateTime.now()) + ".xls");
newResource.setMIMEType("application/vnd.ms-excel");
browserWindowOpener.setResource(newResource);
});
browserWindowOpener.extend(downloadButton);
IMPORTANT: One thing that is mandatory for this to work is to use different filenames for every downloaded file, so that we don't use the cache.