Beginner Problem: One UI per Session


I have a question concerning the Scope of a an Vaadin UI object. I assumed that there will be one instance per user session. In my example application however this is not the case. Every time I reload the page in my browser a new UI instance is created and the data of the old one is lost. Is this the normal behavior or am I doing something wrong? The session id does not change if reload the page.

Here is my example:

package master.afb.example;

import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class View extends UI {

    private static final Logger log = LoggerFactory.getLogger(View.class);
    private Label label = new Label();
    private Button button = new Button("clickMe");
    private int counter = 0;

    protected void init(VaadinRequest request) {
        log.debug("New View created");
        this.getPage().setTitle("Hello World");
        label.setCaption("Hello World");
        button.addClickListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                label.setCaption("You cklicked "+ ++counter+" times");

    public Label getLabel() {
        return label;

    public Button getButton() {
        return button;


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="" xmlns:xsi=""
    <display-name>Vaadin Web Application</display-name>
        <description>Vaadin production mode</description>
        <servlet-name>Vaadin Application Servlet</servlet-name>
            <description>Vaadin UI to display</description>
        <servlet-name>Vaadin Application Servlet</servlet-name>

Matthias, use [b]
[font=Courier New]

[/b] annotion with your UI:

public class View extends UI...

See this tutorial:
Preserve On Refresh


There can be multiple UIs per user session. Multiple tabs or otherwise. But if you want to have a UI to survive a page refresh annotate UI with @PreserveOnRefresh