Time for action – preserving application state

Follow these steps to see how easy it is to preserve the state of UI components in Vaadin applications:

  1. Create a new Vaadin project. We are using keepstate as project name.
  2. Code your UI class:
    public class KeepstateUI extends UI {
    
      protected void init(VaadinRequest request) {
        final VerticalLayout layout = new VerticalLayout();
        layout.setMargin(true);
        setContent(layout);
        TextField tf = new TextField(
            "Type, press ENTER, and refresh the browser");
        tf.setImmediate(true);
    
        tf.addValueChangeListener(new ValueChangeListener() {
          public void valueChange(ValueChangeEvent event) {
            Notification.show(
                "Value: " + event.getProperty().getValue());
          }
        });
    
        layout.addComponent(tf);
      }
    
    }
  3. Nothing new so far. Run the application, ...

Get Vaadin 7 UI Design By Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.