aboutsummaryrefslogtreecommitdiffstats
path: root/documentation/articles/CreatingAnApplicationThatPreservesStateOnRefresh.asciidoc
diff options
context:
space:
mode:
authorHenri Muurimaa <henri.muurimaa@gmail.com>2017-09-11 11:57:15 +0300
committerHenri Sara <henri.sara@gmail.com>2017-09-11 11:57:15 +0300
commitfb207248d5567a2661d5729d5149c7c8920a2efa (patch)
tree197085fb374e85ccc7eeb7d7998a7bcba9b09c43 /documentation/articles/CreatingAnApplicationThatPreservesStateOnRefresh.asciidoc
parente83f012cf5f1388dcab9be427575a655769f75e9 (diff)
downloadvaadin-framework-fb207248d5567a2661d5729d5149c7c8920a2efa.tar.gz
vaadin-framework-fb207248d5567a2661d5729d5149c7c8920a2efa.zip
Migrate wiki articles to Vaadin documentation (#9912)
* Vaadin Tutorial For Swing Developers * Setting And Reading Session Attributes * Enabling Server Push * Cleaning Up Resources In A UI * Sending Email From Java Applications * Using Parameters With Views * Optimizing Sluggish UI * Configuring Push For Your Enviroment * Setting And Reading Cookies * Using Polling * Creating An Application That Preserves State On Refresh * Finding The Current UI And Page And Vaadin Session * Sending Events From The Client To The Server Using RPC * Handling Logout * Remember To Set The Locale * Scalable Web Applications * MVC Basics In ITMill Toolkit * Access Control For Views * Customizing The Startup Page In An Application
Diffstat (limited to 'documentation/articles/CreatingAnApplicationThatPreservesStateOnRefresh.asciidoc')
-rw-r--r--documentation/articles/CreatingAnApplicationThatPreservesStateOnRefresh.asciidoc50
1 files changed, 50 insertions, 0 deletions
diff --git a/documentation/articles/CreatingAnApplicationThatPreservesStateOnRefresh.asciidoc b/documentation/articles/CreatingAnApplicationThatPreservesStateOnRefresh.asciidoc
new file mode 100644
index 0000000000..3f33ec3259
--- /dev/null
+++ b/documentation/articles/CreatingAnApplicationThatPreservesStateOnRefresh.asciidoc
@@ -0,0 +1,50 @@
+[[creating-an-application-that-preserves-state-on-refresh]]
+Creating an application that preserves state on refresh
+-------------------------------------------------------
+
+By default, Vaadin 7 does not preserve UI state when the browser page is
+refreshed. This means that the instance number in this example is
+incremented and the text field cleared on every page refresh:
+
+[source,java]
+....
+public class CreatingPreserveState extends UI {
+ private static int instanceCounter = 0;
+
+ private final CssLayout content = new CssLayout();
+
+ @Override
+ public void init(VaadinRequest request) {
+ TextField tf = new TextField("Instance #" + (++instanceCounter));
+ tf.setImmediate(true);
+
+ content.addComponent(tf);
+ setContent(content);
+ }
+}
+....
+
+You can however modify your application to preserve your UI between page
+refreshes with the `@PreserveOnRefresh` annotation like so
+
+[source,java]
+....
+@PreserveOnRefresh
+public class PreserveStateUI extends UI {
+ ...
+}
+....
+
+If you want to reinitialize some part of your application when the page
+is refreshed, you can (starting from Vaadin 7.2) override the refresh
+method in your UI class. This method is called whenever an already
+initialized UI is refreshed.
+
+[source,java]
+....
+@Override
+protected void refresh(VaadinRequest request) {
+ content.addComponent(new Label("UI was refreshed @"
+ + System.currentTimeMillis()));
+}
+....