Class RouteConfiguration
- All Implemented Interfaces:
Serializable
- Since:
- 1.3
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionaddRoutesChangeListener(RoutesChangedListener listener) Add a listener that is notified when routes change for the registry.static RouteConfigurationGet aRouteConfigurationthat edits the application scope routes.static RouteConfigurationforRegistry(RouteRegistry registry) Get aRouteConfigurationfor editing the given RouteRegistry implementation.static RouteConfigurationGet aRouteConfigurationthat edits the session scope routes.Get theRouteDatafor all registered navigation targets.Get the registry that this configuration is working with.Get theRouteDatafor all accessible registered navigation targets with a menu information.getRegisteredAccessibleMenuRoutes(Collection<BeforeEnterListener> accessControls) Get theRouteDatafor all accessible registered navigation targets with a menu information.Gets the registered route class for a given path.Gets the optional navigation target class for a given Location matching with path segments.getTemplate(Class<? extends Component> navigationTarget) Gets the route template for the given target.<T,C extends Component & HasUrlParameter<T>>
StringGet the url string for given navigation target with the parameters in the url.<T,C extends Component & HasUrlParameter<T>>
StringGet the url string for given navigation target with the parameter in the url.Get the registered url string for given navigation target.getUrl(Class<? extends Component> navigationTarget, RouteParameters parameters) Gets the url which navigates to given navigationTarget using given parameters.getUrlBase(Class<? extends Component> navigationTarget) Return the url base without any route parameters.booleanisPathAvailable(String path) Check if the given path is available.booleanisRouteRegistered(Class<? extends Component> route) Check if the route is available as a registered target.voidremoveRoute(Class<? extends Component> navigationTarget) Remove the given navigation target route registration.voidremoveRoute(String path) Remove all registrations for given path.voidremoveRoute(String path, Class<? extends Component> navigationTarget) Remove only the specified navigationTarget from the path and not other targets if they exist for the same path.voidsetAnnotatedRoute(Class<? extends Component> navigationTarget) Giving a navigation target here will handle theRouteannotation to get the path and also register anyRouteAliasthat may be on the class.voidsetParentAnnotatedRoute(String path, Class<? extends Component> navigationTarget) Register a navigation target on the specified path.voidRegister a navigation target with specified path and with no parent layouts.voidsetRoute(String path, Class<? extends Component> navigationTarget, Class<? extends RouterLayout>... parentChain) Register a navigation target with specified path and given parent layout chain.voidsetRoute(String path, Class<? extends Component> navigationTarget, List<Class<? extends RouterLayout>> parentChain) Register a navigation target with specified path and given parent layout chain.voidBlock updates to the registry configuration from other threads until update command has completed.
-
Method Details
-
forSessionScope
Get aRouteConfigurationthat edits the session scope routes. This requires thatVaadinSession.getCurrent()is populated.Note! Session scoped registry sees also the application scope routes.
- Returns:
- configurator for session scope routes
-
forApplicationScope
Get aRouteConfigurationthat edits the application scope routes. This requires thatVaadinServlet.getCurrent()is populated.- Returns:
- configurator for application scope routes
-
forRegistry
Get aRouteConfigurationfor editing the given RouteRegistry implementation. This enables editing of registry when the requiredCurrentInstanceis not yet populated.- Parameters:
registry- registry to edit through the controller- Returns:
- configurator for editing given registry
-
getAvailableRoutes
Get theRouteDatafor all registered navigation targets.Note! This would be best to request for session scope registry as it will then contain the actual currently visible routes from both the session and application scopes.
Note! Size of the list is only main routes as RouteData will contain a list of alias route registrations.
- Returns:
- list of all routes available
-
isPathAvailable
Check if the given path is available.- Parameters:
path- path to check for availability- Returns:
- true if there exists a route for the given path
-
isRouteRegistered
Check if the route is available as a registered target.- Parameters:
route- target class to check for registration- Returns:
- true if class is registered
-
getRoute
Gets the registered route class for a given path. Returns an empty optional if no navigation target corresponds to the given path.- Parameters:
path- path to get route for- Returns:
- optional containing the path component or empty if not found
-
getRoute
Gets the optional navigation target class for a given Location matching with path segments.- Parameters:
path- path to get navigation target for, notnullsegments- segments given for path- Returns:
- optional navigation target corresponding to the given path and segments
-
addRoutesChangeListener
Add a listener that is notified when routes change for the registry.- Parameters:
listener- listener to add- Returns:
- registration for removing the listener
-
update
Block updates to the registry configuration from other threads until update command has completed.Using this method makes the registry changes made inside the command atomic for the registry as no one else can change the state during the duration of the command.
Any other configuration thread for the same registry will be blocked until all the update locks have been released.
Note! During an update other threads will get the pre-update state of the registry until the update has fully completed.
- Parameters:
command- command to execute for the update
-
setAnnotatedRoute
Giving a navigation target here will handle theRouteannotation to get the path and also register anyRouteAliasthat may be on the class.- Parameters:
navigationTarget- navigation target to register- Throws:
InvalidRouteConfigurationException- thrown if exact route already defined in this scope
-
setParentAnnotatedRoute
Register a navigation target on the specified path. AnyParentLayoutannotation on class will be used to populate layout chain, butRouteandRouteAliaswill not be taken into consideration.- Parameters:
path- path to register navigation target tonavigationTarget- navigation target to register- Throws:
InvalidRouteConfigurationException- thrown if exact route already defined in this scope
-
setRoute
Register a navigation target with specified path and with no parent layouts.Note! Any
ParentLayout,RouteorRouteAliaswill be ignored in route handling.- Parameters:
path- path to register navigation target tonavigationTarget- navigation target to register- Throws:
InvalidRouteConfigurationException- thrown if exact route already defined in this scope
-
setRoute
public void setRoute(String path, Class<? extends Component> navigationTarget, List<Class<? extends RouterLayout>> parentChain) Register a navigation target with specified path and given parent layout chain.Note! Any
ParentLayout,RouteorRouteAliaswill be ignored in route handling.- Parameters:
path- path to register navigation target tonavigationTarget- navigation target to registerparentChain- chain of parent layouts that should be used with this target- Throws:
InvalidRouteConfigurationException- thrown if exact route already defined in this scope
-
setRoute
public void setRoute(String path, Class<? extends Component> navigationTarget, Class<? extends RouterLayout>... parentChain) Register a navigation target with specified path and given parent layout chain.Note! Any
ParentLayout,RouteorRouteAliaswill be ignored in route handling.- Parameters:
path- path to register navigation target tonavigationTarget- navigation target to registerparentChain- chain of parent layouts that should be used with this target- Throws:
InvalidRouteConfigurationException- thrown if exact route already defined in this scope
-
removeRoute
Remove the given navigation target route registration. Path where the navigation target was may still be usable, e.g. we remove target with url param and there is left a non param target, but will not return the removed target.Note! this will remove target route and if possible any
RouteAliasroute that can be found for the class.- Parameters:
navigationTarget- navigation target class to remove
-
removeRoute
Remove all registrations for given path. This means that any navigation target registered on the given path will be removed. But if a removed navigationTarget for the path exists it is then stored with a new main path so it can still get a resolved url.E.g. path "home" contains HomeView and DetailsView[String path param] both will be removed.
Note! The restored path will be the first found match for all paths that are registered.
In case navigationTarget is a
HasUrlParameter, path argument needs to include the parameter placeholder which is added automatically. Otherwise, usingremoveRoute(String, Class)is preferred in such a case.- Parameters:
path- path for which to remove all navigation targets
-
removeRoute
Remove only the specified navigationTarget from the path and not other targets if they exist for the same path.Note! If another path exists for the removed navigation target it will get a new main path so it can still get a resolved url. The restored path will be the first found match for all paths that are registered.
- Parameters:
path- path to remove from registrynavigationTarget- path navigation target to remove
-
getHandledRegistry
Get the registry that this configuration is working with.- Returns:
- handled RouteRegistry
-
getUrl
Get the registered url string for given navigation target.Note! If the navigation target has a url parameter that is required then this method will throw an IllegalArgumentException.
- Parameters:
navigationTarget- navigation target to get url for- Returns:
- url for the navigation target
- Throws:
IllegalArgumentException- if the navigation target requires a parameter
-
getUrlBase
Return the url base without any route parameters.- Parameters:
navigationTarget- navigation target to get url for- Returns:
- optional url base without route parameters or empty if there is
no registered route for
navigationTarget, notnull
-
getTemplate
Gets the route template for the given target.- Parameters:
navigationTarget- target class.- Returns:
- main template for the given target.
-
getUrl
public <T,C extends Component & HasUrlParameter<T>> String getUrl(Class<? extends C> navigationTarget, T parameter) Get the url string for given navigation target with the parameter in the url.Note! Given parameter is checked for correct class type. This means that if the navigation target defined parameter is of type
Booleanthen calling getUrl with aStringwill fail.- Type Parameters:
T- url parameter typeC- navigation target type- Parameters:
navigationTarget- navigation target to get url forparameter- parameter to embed into the generated url- Returns:
- url for the navigation target with parameter
-
getUrl
public <T,C extends Component & HasUrlParameter<T>> String getUrl(Class<? extends C> navigationTarget, List<T> parameters) Get the url string for given navigation target with the parameters in the url.Note! Given parameters are checked for correct class type. This means that if the navigation target defined parameter is of type
Booleanthen calling getUrl with aStringwill fail.- Type Parameters:
T- url parameter typeC- navigation target type- Parameters:
navigationTarget- navigation target to get url forparameters- parameters to embed into the generated url, not null- Returns:
- url for the navigation target with parameter
-
getUrl
Gets the url which navigates to given navigationTarget using given parameters.- Parameters:
navigationTarget- navigation target.parameters- route parameters.- Returns:
- the url which navigates to given navigationTarget using given parameters.
- Throws:
NotFoundException- in case the navigationTarget is not registered with a url template matching the given parameters.
-
getRegisteredAccessibleMenuRoutes
Get theRouteDatafor all accessible registered navigation targets with a menu information. Access checking depends on the activeVaadinServiceandVaadinRequest.Automatically adds access controls from UI if available.
- Returns:
- list of accessible menu routes available for handled registry
-
getRegisteredAccessibleMenuRoutes
public List<RouteData> getRegisteredAccessibleMenuRoutes(Collection<BeforeEnterListener> accessControls) Get theRouteDatafor all accessible registered navigation targets with a menu information. Access checking depends on the activeVaadinServiceandVaadinRequestand the given collection of access controls.- Parameters:
accessControls- the access controls to use for checking access- Returns:
- list of accessible menu routes available for handled registry
-