Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

CreatingAnApplicationThatPreservesStateOnRefresh.asciidoc 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. ---
  2. title: Creating An Application That Preserves State On Refresh
  3. order: 19
  4. layout: page
  5. ---
  6. [[creating-an-application-that-preserves-state-on-refresh]]
  7. = Creating an application that preserves state on refresh
  8. By default, Vaadin 7 does not preserve UI state when the browser page is
  9. refreshed. This means that the instance number in this example is
  10. incremented and the text field cleared on every page refresh:
  11. [source,java]
  12. ....
  13. public class CreatingPreserveState extends UI {
  14. private static int instanceCounter = 0;
  15. private final CssLayout content = new CssLayout();
  16. @Override
  17. public void init(VaadinRequest request) {
  18. TextField tf = new TextField("Instance #" + (++instanceCounter));
  19. tf.setImmediate(true);
  20. content.addComponent(tf);
  21. setContent(content);
  22. }
  23. }
  24. ....
  25. You can however modify your application to preserve your UI between page
  26. refreshes with the `@PreserveOnRefresh` annotation like so
  27. [source,java]
  28. ....
  29. @PreserveOnRefresh
  30. public class PreserveStateUI extends UI {
  31. ...
  32. }
  33. ....
  34. If you want to reinitialize some part of your application when the page
  35. is refreshed, you can (starting from Vaadin 7.2) override the refresh
  36. method in your UI class. This method is called whenever an already
  37. initialized UI is refreshed.
  38. [source,java]
  39. ....
  40. @Override
  41. protected void refresh(VaadinRequest request) {
  42. content.addComponent(new Label("UI was refreshed @"
  43. + System.currentTimeMillis()));
  44. }
  45. ....