Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vaadin open link in new tab

Tags:

java

vaadin

I have the following piece of code that I wrote using Vaadin. The code opens the page www.google.com when the user clicks the button.

My question is is there any way for me to specify that the page is to be opened in a new tab?

Thanks.

button.addClickListener(new Button.ClickListener() {
    public void buttonClick(ClickEvent event) {
        getUI().getPage().setLocation("http://www.google.com");
    }
});
like image 796
user3702643 Avatar asked Jun 04 '14 13:06

user3702643


People also ask

How do I redirect to another page in vaadin?

redirecting can be done with UI. getCurrent(). navigate("") session context can be controlled as explained on https://vaadin.com/docs/v8/framework/articles/SettingAndReadingSessionAttributes.html.

How do I redirect a new tab in Java?

If you want page to open in new browser tab, set the target to be "_blank". See the Anchor. setHref(..)

Is vaadin stateless?

Vaadin Fusion: StatelessBy default, Fusion will not create server sessions and will use the token-based authentication mechanism, keeping the server stateless. Since server endpoints don't use a session, a server can handle more concurrent users, enabling easier horizontal scaling and high availability of services.


2 Answers

getUI().getPage().open("http://www.google.com", "_blank");

The _blank window name is important here. Beware that you may also have browsers that will might open the resource in a new window instead.

There is also another signature to the open() method, i.e.

open(String url, String windowName, boolean tryToOpenAsPopup) 

that may fit the bill. HTH.

References: Page (Vaadin 7.2.1 API).

like image 82
VH-NZZ Avatar answered Oct 12 '22 13:10

VH-NZZ


Try the following code:

BrowserWindowOpener opener = new BrowserWindowOpener(new ExternalResource(url));
opener.setFeatures("");
opener.extend(button);
like image 39
sreg Avatar answered Oct 12 '22 14:10

sreg