Keeping state after refresh
By default, every time you reload the application on the browser, the init
method will be called and all the components will be created again. That means that on every refresh, the components will lose their stored values, or more generally, your application won't preserve its state. For example, if we have an application with a TextField
and the user types some text on it before using the infamous refresh button in the browser, the text previously typed in the TextField
will be lost forever. The same happens with navigators, as each time we navigate to a view, a refresh will happen in the browser.
In order to preserve the state in our Vaadin applications, we have to create a database and store the value for every component we create and every user we have... Just kidding! Preserving the state in Vaadin applications is one of the easiest tasks to do in the history of mankind. Let's see it in action.