Time for action – navigating programmatically
Our website is ready to include some links on it. We will add links to Page 1 and Page 2 inside the Welcome page.
We want to add links to the Welcome page, so we need to edit
Welcome.java
. First we need anavigator
to navigate to the other pages (we will initialize thisnavigator
instance later):public class Welcome extends VerticalLayout implements View { private Navigator navigator; // ... }
We are adding buttons and a button without a click listener is like a heart without a beat (seems to be that writer is getting crazy again). So let's code a
listener
that calls ournavigator
:public class Welcome extends VerticalLayout implements View { // ... public Welcome() { ClickListener listener = new ClickListener() { @Override public void buttonClick(ClickEvent event) { navigator.navigateTo(event.getButton().getCaption()); } }; // ... } }
Now we have our click listener and a click listener without...