Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
BrowserWindowOpener in a Menu
Hi, I have a menu with lots of items.
I need to open a new tab in the browser when I click on that item.
As far as I know, the only way to open new tabs and not be blocked by the browser is to use a BrowserWindowOpener, but the BrowserWindowOpener can only extend components, and a MenuItem is not a component.
I had thought of adding the opener to the whole menu and do some processing of what to open in the new tab, but when clicking to open a submenu it also opens a new tab of course. I was thinking that maybe there was some way to cancel the operation before the tab is opened. I have seen in a post that the getState() method in BrowserWindowOpener happens before the tab is open, so I thought that maybe I could override that method and stop the opening of the tab if necessary?
My ultimate goal is to open a new tab that is not blocked by the browsers when clicking on a menu item. I accept all kind of ideas.
I noticed this is a question I myself am trying to resolve, but unfortunatedly there were no replies. Did you happen to solve the problem?
I too have a use case for opening up a window from a menu item command rather than a button....
Unfortunately I never found a solution for this, but if you find it, please update this post, I am still interested on it
I had to work around it with css, using a button to look like a menubar item.
Thank you for sharing. Unfortunately that won't work for me, since I have several levels of submenus
What I need it's even trickier, because I need to archieve this in a ContextMenu (right-click menu). So I can't use Reuben's trick, too. Any hint would be really appreciated.
One possible workaround is using a html link (<a target="_blank" href="...">) and HTML content in the item. It'll need some styling and you can't use an additional click listener on top of that, but sometimes that might be enough.
Thanks Olli. In fact that was one of the approaches I tried. The problem is that what I want to open in the new browser window (well, it's really a new tab) is a new UI from the same app. I know how to do it, and how to reference it with a custom "path", via a new BrowserWindowOpener(MySecondaryUI.class, "myCustomPath"), and the new opened window/tab will have this path, but I don't know how to "create" that same UI / path and then make it accessible directly when putting it in the address bar of the browser, so I can put it in the href attribute of the link.
I suspect it could be possible using something related to Navigator or even with an UI provider, but I'm really lost at this point. Read something about the later but discarded when realized that I would need to create a new widgetset, etc., started to look overcomplicated and thought that maybe it wouldn't be what I need. Any hint would be, again, much appreciated.
By the way, I don't understand neither why a BrowserWindowOpener cannot extend a MenuItem nor why a button cannot be placed inside a ContextMenu. It again makes things difficult :(
I too have exactly the same requirement as the original poster. To me this seems like a pretty obvious requirement in that functionality of a button should be similar to that of a menu item. From a high level point of view they are similar, but again Vaadin chooses to allow implemention details to impact their API and frustate the development experience.
Any solution for this yet?