public interface ViewNavigator extends Serializable
View configuration and display. Extends the features and the behaviour of
a standard Vaadin Navigator component.
View parameters will be automatically injected in View instance using ViewParameter annotated fields.
Supported parameter value types are:
StringNumbersBooleanEnum (ordinal value must be used for enum values serialization)Date using date format pattern ViewParameter.DEFAULT_DATE_PATTERNLocalDate using date format pattern ISO local date (yyyy-MM-dd)LocalTime using date format pattern ISO local time (HH:mm:ss)LocalDateTime using date format pattern ISO local date/time ('yyyy-MM-ddTHH:mm:ss')
This navigator provides the navigateTo(String, Map) method to trigger navigation using a Map of parameters
name and values instead of a fully serialized navigation state string.
A navigateInWindow method is provided to display a View using a Window instead of the navigator
default ViewDisplay component.
View display lifecycle can be intercepted by the view instance itself, using OnShow and OnLeave
annotated methods. This methods must be public and provide zero or only one parameter of
ViewNavigator.ViewNavigatorChangeEvent or default ViewChangeListener.ViewChangeEvent type. The OnShow annotated method will be
called when the View is displayed in application interface, the OnLeave annotated methods will be called when
the View is about to be deactivated to be replaced by another view in the navigation flow.
This navigator is expected to keep a history of the navigation states of the navigation flow, allowing to navigate
back in navigation history using navigateBack() method.
If correctly configured in concrete subclasses, navigateToDefault() allow to navigate to a predefined
default View (something like a homepage View).
Sub-view are supported, i.e. View instances intended to be displayed in a parent View which must implement
SubViewContainer interface and take care of sub view instances display in application UI. Sub view are
declared using SubViewOf annotation on View classes.
DefaultViewNavigator| Modifier and Type | Interface and Description |
|---|---|
static interface |
ViewNavigator.Builder
Builder to create
ViewNavigator instances |
static interface |
ViewNavigator.NavigationBuilder
Builder to create navigation calls using view name and parameters
|
static interface |
ViewNavigator.NavigatorBuilder<B extends ViewNavigator.NavigatorBuilder<B>>
Base
ViewNavigator builder |
static class |
ViewNavigator.ViewNavigationException
Exception related to
View navigation errors. |
static interface |
ViewNavigator.ViewNavigatorChangeEvent
View change event.
|
| Modifier and Type | Field and Description |
|---|---|
static String |
CONTEXT_KEY
Default
Context resource reference |
static String |
VIEW_URI_SCHEME
URI scheme which represents a navigation to a
View. |
| Modifier and Type | Method and Description |
|---|---|
void |
addViewChangeListener(com.vaadin.navigator.ViewChangeListener listener)
Listen to changes of the active view
|
static ViewNavigator.Builder |
builder()
Builder to create
ViewNavigator instance in fluent-style mode |
static Optional<ViewNavigator> |
getCurrent()
Get the current
ViewNavigator, if available as Context resource or from current UI. |
com.vaadin.navigator.View |
getCurrentView()
Get current (active) view in navigator.
|
String |
getCurrentViewName()
Get current (active) view name in navigator
|
String |
getDefaultViewName()
Get default view name
|
static com.vaadin.ui.Component |
getViewContent(com.vaadin.navigator.View view)
Helper method to get given
view content: if View is a ViewContentProvider, than
ViewContentProvider.getViewContent() is returned, else if view is a Component, view instance
itself is returned. |
boolean |
navigateBack()
Navigates back to previous
View, if any. |
default com.vaadin.ui.Window |
navigateInWindow(String viewName)
Navigate to the
View identified by given viewName using the same behaviour of
navigateTo(String, Map) but rendering the View contents in an application Window, using default Window
configuration. |
default com.vaadin.ui.Window |
navigateInWindow(String viewName,
Consumer<ViewWindowConfigurator> windowConfiguration)
Navigate to the
View identified by given viewName using the same behaviour of
navigateTo(String, Map) but rendering the View contents in an application Window, using optional
windowConfiguration to setup Window features. |
com.vaadin.ui.Window |
navigateInWindow(String viewName,
Consumer<ViewWindowConfigurator> windowConfiguration,
Map<String,Object> parameters)
Navigate to the
View identified by given viewName using the same behaviour of
navigateTo(String, Map) but rendering the View contents in an application Window, using optional
windowConfiguration to setup Window features. |
default com.vaadin.ui.Window |
navigateInWindow(String viewName,
Map<String,Object> parameters)
Navigate to the
View identified by given viewName using the same behaviour of
navigateTo(String, Map) but rendering the View contents in an application Window, using default Window
configuration. |
default void |
navigateTo(String viewName)
Navigates to the
View identified by given viewName. |
void |
navigateTo(String viewName,
Map<String,Object> parameters)
Navigates to the
View identified by given viewName using given parameters, if
any, and linking them to View fields using ViewParameter annotated view class fields. |
void |
navigateToDefault()
Navigates to the default View
|
void |
navigateToState(String navigationState)
Navigates to a view and initialize the view with given parameters.
|
void |
removeViewChangeListener(com.vaadin.navigator.ViewChangeListener listener)
Removes a view change listener
|
static ViewNavigator |
require()
Requires the current
ViewNavigator. |
default ViewNavigator.NavigationBuilder |
toView(String viewName)
Get a
ViewNavigator.NavigationBuilder to create a navigation declaration to navigate to given viewName
using parameters. |
static final String CONTEXT_KEY
Context resource referencestatic final String VIEW_URI_SCHEME
View.void navigateToState(String navigationState)
The navigationState string consists of a view name optionally followed by a slash and a parameters
part that is passed as-is to the view. ViewProviders are used to find and create the correct type of view.
If multiple providers return a matching view, the view with the longest name is selected. This way, e.g. hierarchies of subviews can be registered like "admin/", "admin/users", "admin/settings" and the longest match is used.
If the view being deactivated indicates it wants a confirmation for the navigation operation, the user is asked for the confirmation.
Registered ViewChangeListeners are called upon successful view change.
navigationState - View name and parametersvoid navigateTo(String viewName, Map<String,Object> parameters) throws ViewNavigator.ViewNavigationException
View identified by given viewName using given parameters, if
any, and linking them to View fields using ViewParameter annotated view class fields.
If the view being deactivated indicates it wants a confirmation for the navigation operation, the user is asked for the confirmation.
Registered ViewChangeListeners are called upon successful view change.
viewName - View nameparameters - Optional view parametersViewNavigator.ViewNavigationException - View with given name cannot be found or other view handling errordefault void navigateTo(String viewName) throws ViewNavigator.ViewNavigationException
View identified by given viewName.
If the view being deactivated indicates it wants a confirmation for the navigation operation, the user is asked for the confirmation.
Registered ViewChangeListeners are called upon successful view change.
viewName - View nameViewNavigator.ViewNavigationException - View with given name cannot be found or other view handling errorcom.vaadin.ui.Window navigateInWindow(String viewName, Consumer<ViewWindowConfigurator> windowConfiguration, Map<String,Object> parameters) throws ViewNavigator.ViewNavigationException
View identified by given viewName using the same behaviour of
navigateTo(String, Map) but rendering the View contents in an application Window, using optional
windowConfiguration to setup Window features.viewName - View namewindowConfiguration - View Window configuratorparameters - Optional view parametersViewNavigator.ViewNavigationException - View with given name cannot be found or other view handling errordefault com.vaadin.ui.Window navigateInWindow(String viewName, Map<String,Object> parameters) throws ViewNavigator.ViewNavigationException
View identified by given viewName using the same behaviour of
navigateTo(String, Map) but rendering the View contents in an application Window, using default Window
configuration.viewName - View nameparameters - Optional view parametersViewNavigator.ViewNavigationException - View with given name cannot be found or other view handling errordefault com.vaadin.ui.Window navigateInWindow(String viewName, Consumer<ViewWindowConfigurator> windowConfiguration) throws ViewNavigator.ViewNavigationException
View identified by given viewName using the same behaviour of
navigateTo(String, Map) but rendering the View contents in an application Window, using optional
windowConfiguration to setup Window features.viewName - View namewindowConfiguration - View Window configuratorViewNavigator.ViewNavigationException - View with given name cannot be found or other view handling errordefault com.vaadin.ui.Window navigateInWindow(String viewName) throws ViewNavigator.ViewNavigationException
View identified by given viewName using the same behaviour of
navigateTo(String, Map) but rendering the View contents in an application Window, using default Window
configuration.viewName - View nameViewNavigator.ViewNavigationException - View with given name cannot be found or other view handling errorboolean navigateBack()
throws ViewNavigator.ViewNavigationException
View, if any. In no previous View is available and a default view is defined,
navigator will navigate to the default view.true if a previous view in navigation history, or the default view, was available and back
navigation succeededViewNavigator.ViewNavigationException - View handling errorvoid navigateToDefault()
throws ViewNavigator.ViewNavigationException
ViewNavigator.ViewNavigationException - If no default View is available or other view handling errordefault ViewNavigator.NavigationBuilder toView(String viewName)
ViewNavigator.NavigationBuilder to create a navigation declaration to navigate to given viewName
using parameters.viewName - View name (not null)String getDefaultViewName()
null if not definedString getCurrentViewName()
null if no view is currently active in navigatorcom.vaadin.navigator.View getCurrentView()
Note that this methods returns always the current top-level View in navigator: this means that sub-view instances
will be never returned. To obtain current sub-view check if returned View is a SubViewContainer instance
and than call SubViewContainer.getCurrentView() method.
null if no view is currently active in navigatorvoid addViewChangeListener(com.vaadin.navigator.ViewChangeListener listener)
listener - Listener to invoke during a view changevoid removeViewChangeListener(com.vaadin.navigator.ViewChangeListener listener)
listener - Listener to removestatic Optional<ViewNavigator> getCurrent()
ViewNavigator, if available as Context resource or from current UI.static ViewNavigator require()
ViewNavigator. If not available using getCurrent(), an
IllegalStateException is thrown.IllegalStateException - ViewNavigator is not available as a Context resource of from current UIstatic ViewNavigator.Builder builder()
ViewNavigator instance in fluent-style modestatic com.vaadin.ui.Component getViewContent(com.vaadin.navigator.View view)
view content: if View is a ViewContentProvider, than
ViewContentProvider.getViewContent() is returned, else if view is a Component, view instance
itself is returned. Otherwise, a IllegalArgumentException is thrown.view - View for which retrieve the contentComponent, or null if given view was nullIllegalArgumentException - if view instance is not a ViewContentProvider nor a ComponentCopyright © 2019 The Holon Platform. All rights reserved.