From 4e5c3181b5465bfb37a5f616656b239b3e98f798 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Johannes=20Dahlstr=C3=B6m?= Date: Thu, 22 Nov 2012 14:47:24 +0200 Subject: [PATCH] Kickstart navigation automatically after UI.init(), remove Navigator.navigate() (#9549, 10239) Change-Id: I3537eb8f289e75234d6a292636019429967280c3 --- .../src/com/vaadin/navigator/Navigator.java | 64 ++++++++----------- server/src/com/vaadin/ui/UI.java | 6 ++ .../vaadin/tests/navigator/NavigatorTest.java | 2 - 3 files changed, 33 insertions(+), 39 deletions(-) diff --git a/server/src/com/vaadin/navigator/Navigator.java b/server/src/com/vaadin/navigator/Navigator.java index acfaf45516..72128adddf 100644 --- a/server/src/com/vaadin/navigator/Navigator.java +++ b/server/src/com/vaadin/navigator/Navigator.java @@ -360,20 +360,18 @@ public class Navigator implements Serializable { /** * Creates a navigator that is tracking the active view using URI fragments - * of the current {@link Page} and replacing the contents of a - * {@link ComponentContainer} with the active view. - *

- * In case the container is not on the current page, use another - * {@link Navigator#Navigator(Page, ViewDisplay)} with an explicitly created - * {@link ComponentContainerViewDisplay}. + * of the {@link Page} containing the given UI and replacing the contents of + * a {@link ComponentContainer} with the active view. *

* All components of the container are removed each time before adding the * active {@link View}. Views must implement {@link Component} when using * this constructor. *

- * After all {@link View}s and {@link ViewProvider}s have been registered, - * the application should trigger navigation to the current fragment using - * {@link #navigate()}. + * Navigation is automatically initiated after {@code UI.init()} if a + * navigator was created. If at a later point changes are made to the + * navigator, {@code navigator.navigateTo(navigator.getState())} may need to + * be explicitly called to ensure the current view matches the navigation + * state. * * @param ui * The UI to which this Navigator is attached. @@ -387,18 +385,16 @@ public class Navigator implements Serializable { /** * Creates a navigator that is tracking the active view using URI fragments - * of the current {@link Page} and replacing the contents of a - * {@link SingleComponentContainer} with the active view. - *

- * In case the container is not on the current page, use another - * {@link Navigator#Navigator(Page, ViewDisplay)} with an explicitly created - * {@link SingleComponentContainerViewDisplay}. + * of the {@link Page} containing the given UI and replacing the contents of + * a {@link SingleComponentContainer} with the active view. *

* Views must implement {@link Component} when using this constructor. *

- * After all {@link View}s and {@link ViewProvider}s have been registered, - * the application should trigger navigation to the current fragment using - * {@link #navigate()}. + * Navigation is automatically initiated after {@code UI.init()} if a + * navigator was created. If at a later point changes are made to the + * navigator, {@code navigator.navigateTo(navigator.getState())} may need to + * be explicitly called to ensure the current view matches the navigation + * state. * * @param ui * The UI to which this Navigator is attached. @@ -412,11 +408,13 @@ public class Navigator implements Serializable { /** * Creates a navigator that is tracking the active view using URI fragments - * of the Page containing the given UI. + * of the {@link Page} containing the given UI. *

- * After all {@link View}s and {@link ViewProvider}s have been registered, - * the application should trigger navigation to the current fragment using - * {@link #navigate()}. + * Navigation is automatically initiated after {@code UI.init()} if a + * navigator was created. If at a later point changes are made to the + * navigator, {@code navigator.navigateTo(navigator.getState())} may need to + * be explicitly called to ensure the current view matches the navigation + * state. * * @param ui * The UI to which this Navigator is attached. @@ -430,13 +428,14 @@ public class Navigator implements Serializable { /** * Creates a navigator. *

- * When a custom navigation state manager is not needed, use the constructor - * {@link #Navigator(Page, ViewDisplay)} which uses a URI fragment based - * state manager. + * When a custom navigation state manager is not needed, use one of the + * other constructors which use a URI fragment based state manager. *

- * After all {@link View}s and {@link ViewProvider}s have been registered, - * the application should trigger navigation to the current fragment using - * {@link #navigate()}. + * Navigation is automatically initiated after {@code UI.init()} if a + * navigator was created. If at a later point changes are made to the + * navigator, {@code navigator.navigateTo(navigator.getState())} may need to + * be explicitly called to ensure the current view matches the navigation + * state. * * @param ui * The UI to which this Navigator is attached. @@ -456,15 +455,6 @@ public class Navigator implements Serializable { this.display = display; } - /** - * Navigates to the current navigation state. This method should be called - * when all required {@link View}s, {@link ViewProvider}s, and - * {@link ViewChangeListener}s have been added to the navigator. - */ - public void navigate() { - navigateTo(getStateManager().getState()); - } - /** * Navigates to a view and initialize the view with given parameters. *

diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java index a5e8f5e508..89a36e198e 100644 --- a/server/src/com/vaadin/ui/UI.java +++ b/server/src/com/vaadin/ui/UI.java @@ -552,6 +552,12 @@ public abstract class UI extends AbstractSingleComponentContainer implements // Call the init overridden by the application developer init(request); + + Navigator navigator = getNavigator(); + if (navigator != null) { + // Kickstart navigation if a navigator was attached in init() + navigator.navigateTo(navigator.getState()); + } } /** diff --git a/uitest/src/com/vaadin/tests/navigator/NavigatorTest.java b/uitest/src/com/vaadin/tests/navigator/NavigatorTest.java index 08832e5e82..f35c8b876d 100644 --- a/uitest/src/com/vaadin/tests/navigator/NavigatorTest.java +++ b/uitest/src/com/vaadin/tests/navigator/NavigatorTest.java @@ -129,8 +129,6 @@ public class NavigatorTest extends UI { navi.setErrorView(new ErrorView()); - navi.navigate(); - layout.addComponent(new NaviButton("list")); layout.addComponent(new NaviButton("edit")); layout.addComponent(new NaviButton("forbidden")); -- 2.39.5