Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Redirecting a page to another page

K Timot
5 years ago Nov 18, 2016 12:41pm
Johannes Häyry
5 years ago Nov 19, 2016 6:29am

Depends on what scenario do you have. You can do it in a ServletFilter with HttpServletResponse.sendRedirect.
Maybe you want to do it from a UI action in Vaadin app - that would be Page.getCurrent().setLocation(uri).
If you mean navigating to a different view and not a whole http get request, you can use Navigator.navigateTo(urifragment).

Bagus Priyo Wibowo
3 years ago Oct 26, 2018 6:21am
Johannes Häyry
3 years ago Oct 26, 2018 7:49am
Bagus Priyo Wibowo
3 years ago Oct 26, 2018 8:08am
Bagus Priyo Wibowo
3 years ago Oct 26, 2018 8:09am
Johannes Häyry
3 years ago Oct 26, 2018 9:56am

And you are using Vaadin 8 withou CDI or Spring? If that is the case. First you have to setup Navigator as described in https://vaadin.com/docs/v8/framework/advanced/advanced-navigator.html#advanced.navigator

Then you can get Navigator from your UI and navigate to views you have to it.

Button button = new Button("Page 1", event -> UI.getCurrent().getNavigator().navigateTo("page1"));
Bagus Priyo Wibowo
3 years ago Oct 29, 2018 9:21am

i try with Button.ClickListener{....}, but the ClickListener is can not be read,,.. or it Error.

can you help me to find the solution... thanks

Johannes Häyry
3 years ago Oct 29, 2018 11:03am
Bagus Priyo Wibowo
3 years ago Oct 30, 2018 1:52am
Johannes Häyry
3 years ago Oct 30, 2018 8:09am

Apparently you are not using Vaadin 8, which I assumed when pasting my solution. Vaadin 10+ version is:

Button button = new Button("Page 1", event -> UI.getCurrent().navigate("page1"));

And if you don't want to use lambdas and want to create a class for the listener, it's:

import com.vaadin.flow.component.ClickEvent;
import com.vaadin.flow.component.ComponentEventListener;

class ButtonListener implements ComponentEventListener<ClickEvent<Button>> {
	@Override
	public void onComponentEvent(ClickEvent<Button> event) {
	}
}