title: How to change the main view of a Vaadin 7 application?
body: <p>I want to write a Vaadin 7 application (see <em>MyVaadinUI</em> below), which asks the user to enter user name and password.</p>
  
  <p>If they are correct, another view (see <em>MainUI</em> below) should appear and take the entire area (replace the login view).</p>
  
  <p>I tried to implement this transition in the method <em>MyVaadinUI.goToMainWindow</em>, but I get the error</p>
  
  <pre><code>java.lang.RuntimeException: Component must be attached to a session when getConnectorId() is called for the first time
      at com.vaadin.server.AbstractClientConnector.getConnectorId(AbstractClientConnector.java:417)
      at com.vaadin.server.communication.ConnectorHierarchyWriter.write(ConnectorHierarchyWriter.java:67)
      at com.vaadin.server.communication.UidlWriter.write(UidlWriter.java:143)
      at com.vaadin.server.communication.UidlRequestHandler.writeUidl(UidlRequestHandler.java:149)
      at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:97)
      at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:37)
      at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1371)
      at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:238)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
  </code></pre>
  
  <p>when I run the application and press the button.</p>
  
  <p>How can I fix it?</p>
  
  <pre><code>@Theme("mytheme")
  @SuppressWarnings("serial")
  public class MyVaadinUI extends UI
  {
      private TextField userNameTextField;
      private PasswordField passwordTextField;
  
      @WebServlet(value = "/*", asyncSupported = true)
      @VaadinServletConfiguration(productionMode = false, ui = MyVaadinUI.class, widgetset = "ru.mycompany.vaadin.demo.AppWidgetSet")
      public static class Servlet extends VaadinServlet {
      }
  
      @Override
      protected void init(VaadinRequest request) {
          final VerticalLayout layout = new VerticalLayout();
          layout.setMargin(true);
          setContent(layout);
  
          addUserNameTextField(layout);
          addPasswordTextField(layout);
  
          addButton(layout, request);
      }
  
      private void addPasswordTextField(Layout aLayout) {
          passwordTextField = new PasswordField("Пароль:");
  
          aLayout.addComponent(passwordTextField);
  
      }
  
      private void addUserNameTextField(final Layout aLayout) {
          userNameTextField = new TextField("Пользователь:");
  
          aLayout.addComponent(userNameTextField);
      }
  
  
      private void addButton(final Layout aParent, final VaadinRequest request) {
          final Button button = new Button("Войти");
          button.addClickListener(new Button.ClickListener() {
              public void buttonClick(Button.ClickEvent event) {
                  final boolean credentialsCorrect = checkCredentials();
  
                  if (credentialsCorrect) {
                      goToMainWindow(request);
                  } else {
                      [...]
                  }
              }
          });
          aParent.addComponent(button);
      }
  
      private void goToMainWindow(final VaadinRequest aRequest) {
  
          final MainUI mainUI = new MainUI();
          mainUI.init(aRequest);
          setContent(mainUI);
      }
  
  }
  
  @Theme("mytheme")
  @SuppressWarnings("serial")
  public class MainUI extends UI {
      @Override
      protected void init(final VaadinRequest vaadinRequest) {
          final HorizontalSplitPanel splitPanel = new HorizontalSplitPanel();
  
          setContent(splitPanel);
  
          splitPanel.setSizeFull();
          splitPanel.setSplitPosition(200, Unit.PIXELS);
  
          final String[] tabLabels = new String[] {
                  "Tree item 1",
                  "Tree item 2"};
  
          final Tree tree = new Tree();
  
          for (int i=0; i &lt; tabLabels.length; i++)
          {
              addTreeItem(tree, tabLabels[i]);
          }
  
          splitPanel.setFirstComponent(tree);
          splitPanel.setSecondComponent(new Label("Test"));
      }
  
      private void addTreeItem(final Tree aTree, final String aLabel) {
          aTree.addItem(aLabel);
      }
  }
  </code></pre>