You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RefreshUI.java 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package com.vaadin.tests.components.ui;
  2. import com.vaadin.annotations.PreserveOnRefresh;
  3. import com.vaadin.navigator.Navigator;
  4. import com.vaadin.navigator.View;
  5. import com.vaadin.server.VaadinRequest;
  6. import com.vaadin.tests.components.AbstractTestUI;
  7. import com.vaadin.ui.Button;
  8. import com.vaadin.ui.Label;
  9. import com.vaadin.ui.UI;
  10. import com.vaadin.ui.VerticalLayout;
  11. @PreserveOnRefresh
  12. public class RefreshUI extends AbstractTestUI {
  13. @Override
  14. protected void setup(VaadinRequest request) {
  15. final Navigator navigator = new Navigator(this, this);
  16. navigator.addView("", MyView.class);
  17. navigator.addView("otherview", OtherView.class);
  18. setNavigator(navigator);
  19. MyView.instanceNumber = 0;
  20. OtherView.instanceNumber = 0;
  21. }
  22. public static class MyView extends VerticalLayout implements View {
  23. private static int instanceNumber = 0;
  24. public MyView() {
  25. instanceNumber++;
  26. addComponent(new Label("This is instance no " + instanceNumber));
  27. addComponent(new Button("Navigate to otherview", e -> UI
  28. .getCurrent().getNavigator().navigateTo("otherview")));
  29. }
  30. }
  31. public static class OtherView extends VerticalLayout implements View {
  32. private static int instanceNumber = 0;
  33. public OtherView() {
  34. instanceNumber++;
  35. addComponent(new Label(
  36. "This is otherview instance no " + instanceNumber));
  37. }
  38. }
  39. }