Time for action – using navigators
Let's pour some architectural sugar:
Create a new Vaadin project. We are using navigator as project name.
Implement a
view
for the Welcome page:public class Welcome extends VerticalLayout implements View { public Welcome() { addComponent(new Label("Welcome")); } @Override public void enter(ViewChangeEvent event) { Notification.show("Showing Welcome page"); } }
Implement a view for the
Page1
class:public class Page1 extends VerticalLayout implements View { public Page1() { addComponent(new Label("Page 1")); } @Override public void enter(ViewChangeEvent event) { Notification.show("Showing page 1"); } }
Use the previous
Page1
class to implement aPage2
class. Don't forget to change the label content and the notification accordingly.Now, change your
UI
class to this:public class NavigatorUI extends UI { protected void init(VaadinRequest request) { Navigator navigator = new Navigator(this, this); navigator...