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:
Create a new Vaadin project. We are using keepstate as project name.
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); } }
Nothing new so far. Run the application, type some text in the text field, and press Enter. You will see something like this:
Now, refresh the browser and watch out how some text is gone:
What we want is to...