How to use Navigator in a View?

I have a Vaadin 7 + Grails application with a
UI
and two
Views
. In the UI there is a
Navigator
instance:

@Override
protected void init(VaadinRequest vaadinRequest) {
    Navigator navigator = new Navigator(this, this)

    navigator.addView(MainView.NAME, new MainView())

    navigator.addView(CountView.NAME, CountView.class)

}

Now I want to create a
Button
in my
MainView
which should redirect the user to the
CountView
. I’ve added a
Button.CLickListener
to my buton, but the problem is I don’t know how to get hold of the
Navigator
intance in the view nor any other way redirect should be done.

I looked at this page: https://vaadin.com/book/vaadin7/-/page/advanced.navigator.html but in the example there the
navigator
field just pops out of nowhere in the
StartView
class which results in a
no such field
exception for me.

I’ll be grateful if you could provide me an example or give an explanation of how this works.

Found a solution:

getUI().getNavigator().navigateTo("foobar");

or

UI.getCurrent().getNavigator().navigateTo("foobar");