问题
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