Vaadin: open new window with ABSOLUTE url path from a BUTTON

旧巷老猫 提交于 2019-12-23 18:31:38

问题


I have a table with addresses. I have a button you can click which I want to open a google search for the address in a separate window. I have tried this code with BrowserWindowOpener.

getUI().getPage().open(url, "_blank")

and

BrowserWindowOpener opener = new BrowserWindowOpener(url);
opener.extend(googleBtn)

but both are appending my url to the current path. I want to simply run a search in google in a separate window. I'm sure this is much simpler than I'm making it. It sure should be, at least. Thanks.


回答1:


Brimby, you were right with your second try. The BrowserWindowOpener extension is the way to go. You should use an ExternalResource instance with an absolute URL like this:

public class OpenGoogleUI extends UI {
    @Override
    protected void init(VaadinRequest request) {
        BrowserWindowOpener extension = new BrowserWindowOpener(new ExternalResource("https://www.google.by/#q=vaadin"));
        Button button = new Button("Open Google");
        extension.extend(button);
        setContent(button);
    }
}



回答2:


Try this:

// Hyperlink to a given URL
Link link = new Link("Google It",
        new ExternalResource("https://www.google.by/#q=search+query"));

// Open the URL in a new window/tab
link.setTargetName("_blank");


来源:https://stackoverflow.com/questions/23280379/vaadin-open-new-window-with-absolute-url-path-from-a-button

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!