Simple hyperlink from one page to another

Hi all,

I have just started using vaadin and I am having problem in linking second page using Link component. I saw the demo example where it is shown how to add the hyperlink in the application page, but this example is used to link google home page; however i want to link the another application page i have created. I have main application java file called

and i want to link another application java file called

. I’m trying this piece of code-


secondPage sp = new secondPage();

	Link l = new Link("Open Second Page",
            new ExternalResource(sp.getURL()));
			//new ExternalResource(""));
    l.setDescription("Link to Second Page");


This is giving me this error-

java.lang.RuntimeException: Source must be non-null

Can anyone explain the idea behind this and how to create the hyperlink?

Is the both “pages” part of the same application?

Vaadin is more of an application based framework than a page based framework, so you shouldn’t think of it in pages. Have rather SecondPage extend something like VerticalLayout instead of Application, and use a button instead of a link, like:

        Button button = new Button("button", new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                getMainWindow().setContent(new SecondPage());

Also, read the tutorials in the
Book of Vaadin

MVP4Vaadin Add-on
can be used to facilitate navigation (not used yet, but seems promising).
For really page-oriented usage of Vaadin, there is also the
Navigator Add-on

In my case I have created two different classes extending Application class.

Anyways, Let me tell you what i understood from your explanation…

We can’t have two classes extending “Application”. If we want to have two different screens, either we will extend some kind of layout instead of Application or we will declare a separate window instance inside the main application sub class. Is that what u mean?

As stated above, Vaadin is not like JSP where you would have “independent” classes per page. Instead, you have views which are typically layouts, and you switch the window content (or part of it) to switch views. If you need separate URLs for different views, take a look at Navigator, Navigator7, AppFoundation etc. add-ons in the directory - but in many applications, having separate direct URLs for every view is not needed, either. Instead, you can modify the UI in button click or value change listeners etc.

It is possible to have multiple applications in a Vaadin WAR, but in 95% of cases that is not a good way to build a Vaadin based system. It is only really needed in very special cases like needing two different servlets and applications for completely separate desktop and mobile UIs - and even there it is not absolutely necessary. The servlets handling these applications should then be mapped to different context paths if using this approach.

Thanks Henri. This is helpful. -_-

Hi Henri,

I have plans for the near future to extent my
application with a second application using the TouchKit 2.0 for the mobile users. I want to have separate context paths for these different applications.

Now my question: do you think this is not a good idea? You said it’s not absolutely necessary. What would be the other option(s)?



PS: I asked this also

In this case it probably is a good idea to use separate applications if the UIs are very different - one of the few good use cases for this.

It would also be possible to map two different servlets classes to the same application, but then you might not be able to select the correct “mode” (e.g. view class) for the application before the main layout is attached.

There are answers related to other aspects of your question in the other thread.