Vaadin 10 Button redicted to URL

a 夏天 提交于 2019-12-11 03:44:23

问题


On a click on a Button, I need to do some action and then redirect to an external url.

All example I find are for older Vaadin version, and doesn't work on Vaadin 10.

Can someone provide an example please ?


回答1:


In most cases I would recommend you to use the new Anchor component in Vaadin 10+. Its purpose is to cover your use case, replace BrowserWindowOpener, etc.

If your use case is to redirect non-logged in users to external SSO login page, then I would do it differently. I would not do redirecting in logout button, but instead implement it in access control of the views using BeforeEnterEvent, you need to implement BeforeEnterObserver interface in the view and override beforeEnter(..) method as follows:

@Override
public void beforeEnter(BeforeEnterEvent event) {
    if (VaadinSession.getCurrent().getAttribute("userLoggedIn") == null) {
        UI.getCurrent().getPage().executeJavaScript("window.open(\"http://vaadin.com/\", \"_self\");");
    }
}


来源:https://stackoverflow.com/questions/52303909/vaadin-10-button-redicted-to-url

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