Tyvain
Tyvain

Reputation: 2760

Vaadin 10 Button redicted to URL

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 ?

Upvotes: 2

Views: 1816

Answers (1)

Tatu Lund
Tatu Lund

Reputation: 10633

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\");");
    }
}

Upvotes: 2

Related Questions