DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Coding
  3. Java
  4. Use views, not windows in Vaadin

Use views, not windows in Vaadin

Nicolas Fränkel user avatar by
Nicolas Fränkel
CORE ·
Feb. 29, 12 · Interview
Like (0)
Save
Tweet
Share
16.79K Views

Join the DZone community and get the full member experience.

Join For Free
In Vaadin 6, the Window class is used for both main windows - i.e. windows that fill the entire screen, and popup windows aka subwindows.

This has lead some developers (including me) to think main windows could be set and then removed later on: this is not the case and may lead to nasty bugs when the page is refreshed by the user just after having switched main windows.
Note: Vaadin 7 tackles the problem by merging the application and the main window into a single class (more in a later article).

In essence, when one has to fundamentally change what is shown to the user, one should use a custom component I call view. A view is just a group of components that are laid out together. Then, when we need to switch windows, we keep the main window and switch its content from one view to another: the main window becomes a just a placeholder. As an added value, since the main window is kept, it has always access to the parent application.

The application becomes something like this:

public class MyApplication extends Application {
 
  @Override
  public void init() {
 
    setMainWindow(new Window());
  }
}

The view should look something like that:

public class LoginView extends CustomComponent {
 
  private TextField login = new TextField("Login");
 
  private TextField password = new TextField("Password");
 
  public LoginView() {
 
    FormLayout layout = new FormLayout();
 
    setCompositionRoot(layout);
 
    layout.addComponent(login);
    layout.addComponent(password);
 
    Button button = new Button("Login");
 
    layout.addComponent(button);
 
    button.addListener(new ClickListener() {
 
      @Override
      public void buttonClick(ClickEvent event) {
 
        getApplication().getMainWindow().setContent(new MainView());
      }
    });
  }
}

Important notes:

  1. MainView is another custom component with the components we want displayed
  2. don't forget the separation of concerns, the switching behavior mixed in the GUI code is shown only for readability purposes
  3. login in and out should perhaps be designed at the application level so we could call getApplication().login()
Vaadin

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Scaling Your Testing Efforts With Cloud-Based Testing Tools
  • How To Handle Secrets in Docker
  • A First Look at Neon
  • Java REST API Frameworks

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: