Nicolas Frankel is an IT consultant with 10 years experience in Java / JEE environments. He likes his job so much he writes technical articles on his blog and reviews technical books in his spare time. He also tries to find other geeks like him in universities, as a part-time lecturer. Nicolas is a DZone MVB and is not an employee of DZone and has posted 228 posts at DZone. You can read more from them at their website. View Full User Profile

Switching Windows in Vaadin

  • submit to reddit

In my last article, I definitely advised that when needing to radically change components displayed on the screen, you need to switch the main window's contents - the view - and not the window itself.

Fortunately, this confusion is not possible anymore in Vaadin 7 since the application object and the main window are merged into the Root class.

package com.morevaadin.vaadin7.example;
import com.vaadin.terminal.WrappedRequest;
import com.vaadin.ui.Label;
import com.vaadin.ui.Root;
import com.vaadin.ui.VerticalLayout;
public class Vaadin7RootApplication extends Root {
    protected void init(WrappedRequest request) {
        VerticalLayout layout = new VerticalLayout();
        Label label = new Label("Hello Vaadin user");

Note that Root instances have no root content (!): this means we have to set it explicitly, like the layout in the previous snippet.

As a corollary, this also means a Root class has to be configured in the web deployment descriptor for the Vaadin servlet (and not an Application class anymore). This directly translates into the following snippet:

    <servlet-name>Vaadin 7 Root Example</servlet-name>

Conclusion: Vaadin 7 is less confusing than Vaadin 6 for managing full-screen windows. Besides, it achieves the same result in as many lines of code: it's a definite step toward cleaner windows management.

The archive that highlights the above code can be downloaded here.

Note: At the time of this writing, the Eclipse Vaadin plugin doesn't check the Vaadin version and generates the application skeleton adapted to Vaadin 6. Expect to see this corrected with Vaadin 7 release.


Published at DZone with permission of Nicolas Frankel, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)