Vaadin 10 Button redicted to URL

2019-07-16 02:37发布

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条回答
迷人小祖宗
2楼-- · 2019-07-16 03:01

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\");");
    }
}
查看更多
登录 后发表回答