com.vaadin.flow.router.
Class BeforeEvent
- java.lang.Object
-
- java.util.EventObject
-
- com.vaadin.flow.router.BeforeEvent
-
All Implemented Interfaces:
Direct Known Subclasses:
public abstract class BeforeEvent extends EventObject
Abstract before event class that has the common functionalities for
BeforeLeaveEvent
andBeforeEnterEvent
.Since:
1.0
See Also:
-
-
Field Summary
-
Fields inherited from class java.util.EventObject
source
-
-
Constructor Summary
Constructors Constructor and Description BeforeEvent(NavigationEvent event, Class<?> navigationTarget, List<Class<? extends RouterLayout>> layouts)
Constructs event from a NavigationEvent.
BeforeEvent(NavigationEvent event, Class<?> navigationTarget, RouteParameters parameters, List<Class<? extends RouterLayout>> layouts)
Constructs event from a NavigationEvent.
BeforeEvent(Router router, NavigationTrigger trigger, Location location, Class<?> navigationTarget, RouteParameters parameters, UI ui, List<Class<? extends RouterLayout>> layouts)
Constructs a new BeforeEvent.
BeforeEvent(Router router, NavigationTrigger trigger, Location location, Class<?> navigationTarget, UI ui, List<Class<? extends RouterLayout>> layouts)
Constructs a new BeforeEvent.
-
Method Summary
All Methods Modifier and Type Method and Description void
forwardTo(Class<? extends Component> forwardTargetComponent)
Forward the navigation to show the given component instead of the component that is currently about to be displayed.
void
forwardTo(Class<? extends Component> forwardTargetComponent, RouteParameters parameters)
Forward the navigation to show the given component instead of the component that is currently about to be displayed.
void
forwardTo(NavigationHandler forwardTarget, NavigationState targetState)
Forward the navigation to use the provided navigation handler instead of the currently used handler.
void
forwardTo(NavigationState targetState)
Forward the navigation to the given navigation state.
void
forwardTo(String location)
Forward to navigation component registered for given location string instead of the component about to be displayed.
<T> void
forwardTo(String location, List<T> locationParams)
Forward to navigation component registered for given location string with given location parameters instead of the component about to be displayed.
<T> void
forwardTo(String location, T locationParam)
Forward to navigation component registered for given location string with given location parameter instead of the component about to be displayed.
ErrorParameter<?>
getErrorParameter()
Get the set error parameter.
NavigationHandler
getForwardTarget()
Gets the forward target handler to use if the user should be forwarded to some other view.
List<String>
getForwardTargetParameters()
Deprecated.
usegetForwardTargetRouteParameters()
instead.RouteParameters
getForwardTargetRouteParameters()
Gets the URL parameters of the forward target.
Class<? extends Component>
getForwardTargetType()
Get the forward target type for forwarding.
String
getForwardUrl()
Gets the reroute url.
List<Class<? extends RouterLayout>>
getLayouts()
Get the layout chain for the
navigation target
.Location
getLocation()
Gets the new location.
Class<?>
getNavigationTarget()
Get the navigation target.
NavigationHandler
getRerouteTarget()
Gets the reroute target handler to use if the user should be rerouted to some other view.
List<String>
getRerouteTargetParameters()
Deprecated.
usegetRerouteTargetRouteParameters()
instead.RouteParameters
getRerouteTargetRouteParameters()
Get the URL parameters of the reroute target.
Class<? extends Component>
getRerouteTargetType()
Get the route target type for rerouting.
String
getRerouteUrl()
Gets the reroute url.
RouteParameters
getRouteParameters()
Gets the route parameters associated with this event.
Class<? extends Component>
getRouteTargetType()
Deprecated.
usegetRerouteTargetType()
instead.Router
getSource()
NavigationTrigger
getTrigger()
Gets the type of user action that triggered this location change.
UI
getUI()
Gets the UI this navigation takes place inside.
String
getUnknownForward()
Gets the unknown forward.
String
getUnknownReroute()
Gets the unknown reroute.
boolean
hasErrorParameter()
Check if we have an error parameter set for this navigation event.
boolean
hasForwardTarget()
Check if we have a forward target.
boolean
hasRerouteTarget()
Check if we have a reroute target.
boolean
hasUnknownForward()
Gets if forward route is unknown.
boolean
hasUnknownReroute()
Gets if reroute route is unknown.
void
rerouteTo(Class<? extends Component> routeTargetType)
Reroutes the navigation to show the given component instead of the component that is currently about to be displayed.
void
rerouteTo(Class<? extends Component> routeTargetType, RouteParameters parameters)
Reroutes the navigation to show the given component instead of the component that is currently about to be displayed.
void
rerouteTo(NavigationHandler rerouteTarget, NavigationState targetState)
Reroutes the navigation to use the provided navigation handler instead of the currently used handler.
void
rerouteTo(NavigationState targetState)
Reroutes the navigation to the given navigation state.
void
rerouteTo(String route)
Reroute to navigation component registered for given location string instead of the component about to be displayed.
<T> void
rerouteTo(String route, List<T> routeParams)
Reroute to navigation component registered for given location string with given route parameters instead of the component about to be displayed.
<T> void
rerouteTo(String route, T routeParam)
Reroute to navigation component registered for given location string with given route parameter instead of the component about to be displayed.
void
rerouteToError(Class<? extends Exception> exception)
Reroute to error target for given exception without custom message.
void
rerouteToError(Class<? extends Exception> exception, String customMessage)
Reroute to error target for given exception with given custom message.
void
rerouteToError(Exception exception, String customMessage)
Reroute to error target for given exception with given custom message.
-
Methods inherited from class java.util.EventObject
toString
-
-
-
-
Constructor Detail
-
BeforeEvent
public BeforeEvent(NavigationEvent event, Class<?> navigationTarget, List<Class<? extends RouterLayout>> layouts)
Constructs event from a NavigationEvent.
Parameters:
event
- NavigationEvent that is on-going, notnull
navigationTarget
- navigation target, notnull
layouts
- Navigation layout chain, notnull
-
BeforeEvent
public BeforeEvent(NavigationEvent event, Class<?> navigationTarget, RouteParameters parameters, List<Class<? extends RouterLayout>> layouts)
Constructs event from a NavigationEvent.
Parameters:
event
- NavigationEvent that is on-going, notnull
navigationTarget
- navigation target, notnull
parameters
- route parameters, notnull
layouts
- Navigation layout chain, notnull
-
BeforeEvent
public BeforeEvent(Router router, NavigationTrigger trigger, Location location, Class<?> navigationTarget, UI ui, List<Class<? extends RouterLayout>> layouts)
Constructs a new BeforeEvent.
Parameters:
router
- the router that triggered the change, notnull
trigger
- the type of user action that triggered this location change, notnull
location
- the new location, notnull
navigationTarget
- navigation target class, notnull
ui
- the UI related to the navigation, notnull
layouts
- the layout chain for the navigation target, notnull
-
BeforeEvent
public BeforeEvent(Router router, NavigationTrigger trigger, Location location, Class<?> navigationTarget, RouteParameters parameters, UI ui, List<Class<? extends RouterLayout>> layouts)
Constructs a new BeforeEvent.
Parameters:
router
- the router that triggered the change, notnull
trigger
- the type of user action that triggered this location change, notnull
location
- the new location, notnull
navigationTarget
- navigation target class, notnull
parameters
- route parameters, notnull
ui
- the UI related to the navigation, notnull
layouts
- the layout chain for the navigation target, notnull
-
-
Method Detail
-
hasUnknownForward
public boolean hasUnknownForward()
Gets if forward route is unknown. This is true only when a forward route is not found using
forwardTo(String)
method.Returns:
forward route is not found in the route registry.
-
hasUnknownReroute
public boolean hasUnknownReroute()
Gets if reroute route is unknown. This is true only when a reroute route is not found using
rerouteTo(String)
method.Returns:
reroute is not found in the route registry.
-
getUnknownForward
public String getUnknownForward()
Gets the unknown forward.
Returns:
the unknown forward.
-
getUnknownReroute
public String getUnknownReroute()
Gets the unknown reroute.
Returns:
the unknown reroute.
-
getLocation
public Location getLocation()
Gets the new location.
Returns:
the new location, not
null
-
getTrigger
public NavigationTrigger getTrigger()
Gets the type of user action that triggered this location change.
Returns:
the type of user action that triggered this location change, not
null
-
getSource
public Router getSource()
Overrides:
getSource
in classEventObject
-
hasForwardTarget
public boolean hasForwardTarget()
Check if we have a forward target.
Returns:
forward target exists
-
hasRerouteTarget
public boolean hasRerouteTarget()
Check if we have a reroute target.
Returns:
reroute target exists
-
getForwardTarget
public NavigationHandler getForwardTarget()
Gets the forward target handler to use if the user should be forwarded to some other view.
Returns:
navigation handler
-
getRerouteTarget
public NavigationHandler getRerouteTarget()
Gets the reroute target handler to use if the user should be rerouted to some other view.
Returns:
an navigation handler
-
forwardTo
public void forwardTo(NavigationHandler forwardTarget, NavigationState targetState)
Forward the navigation to use the provided navigation handler instead of the currently used handler.
This function changes the browser URL as opposed to
rerouteTo()
.Note that query parameters of the event are preserved in the forwarded URL.
Parameters:
forwardTarget
- the navigation handler to use, ornull
to clear a previously set forward targettargetState
- the target navigation state of the rerouting
-
forwardTo
public void forwardTo(NavigationState targetState)
Forward the navigation to the given navigation state.
This function changes the browser URL as opposed to
rerouteTo()
.Note that query parameters of the event are preserved in the forwarded URL.
Parameters:
targetState
- the target navigation state, notnull
-
forwardTo
public void forwardTo(Class<? extends Component> forwardTargetComponent)
Forward the navigation to show the given component instead of the component that is currently about to be displayed.
This function changes the browser URL as opposed to
rerouteTo()
.Note that query parameters of the event are preserved in the forwarded URL.
Parameters:
forwardTargetComponent
- the component type to display, notnull
-
forwardTo
public void forwardTo(Class<? extends Component> forwardTargetComponent, RouteParameters parameters)
Forward the navigation to show the given component instead of the component that is currently about to be displayed.
This function changes the browser URL as opposed to
rerouteTo()
.Note that query parameters of the event are preserved in the forwarded URL.
Parameters:
forwardTargetComponent
- the component type to display, notnull
parameters
- parameters for the target url.
-
forwardTo
public void forwardTo(String location)
Forward to navigation component registered for given location string instead of the component about to be displayed.
This function changes the browser URL as opposed to
rerouteTo()
.Note that query parameters of the event are preserved in the forwarded URL.
Parameters:
location
- forward target location string
-
forwardTo
public <T> void forwardTo(String location, T locationParam)
Forward to navigation component registered for given location string with given location parameter instead of the component about to be displayed.
This function changes the browser URL as opposed to
rerouteTo()
.Note that query parameters of the event are preserved in the forwarded URL.
Type Parameters:
T
- location parameter typeParameters:
location
- forward target location stringlocationParam
- location parameter
-
forwardTo
public <T> void forwardTo(String location, List<T> locationParams)
Forward to navigation component registered for given location string with given location parameters instead of the component about to be displayed.
This function changes the browser URL as opposed to
rerouteTo()
.Note that query parameters of the event are preserved in the forwarded URL.
Type Parameters:
T
- location parameters typeParameters:
location
- forward target location stringlocationParams
- location parameters
-
rerouteTo
public void rerouteTo(NavigationHandler rerouteTarget, NavigationState targetState)
Reroutes the navigation to use the provided navigation handler instead of the currently used handler.
This function doesn't change the browser URL as opposed to
forwardTo()
.Note that rerouting preserves the query parameters of the event.
Parameters:
rerouteTarget
- the navigation handler to use, ornull
to clear a previously set reroute targettargetState
- the target navigation state of the rerouting
-
rerouteTo
public void rerouteTo(NavigationState targetState)
Reroutes the navigation to the given navigation state.
This function doesn't change the browser URL as opposed to
forwardTo()
.Note that rerouting preserves the query parameters of the event.
Parameters:
targetState
- the target navigation state of the rerouting, notnull
-
rerouteTo
public void rerouteTo(Class<? extends Component> routeTargetType)
Reroutes the navigation to show the given component instead of the component that is currently about to be displayed.
This function doesn't change the browser URL as opposed to
forwardTo()
.Note that rerouting preserves the query parameters of the event.
Parameters:
routeTargetType
- the component type to display, notnull
-
rerouteTo
public void rerouteTo(Class<? extends Component> routeTargetType, RouteParameters parameters)
Reroutes the navigation to show the given component instead of the component that is currently about to be displayed.
This function doesn't change the browser URL as opposed to
forwardTo()
.Note that rerouting preserves the query parameters of the event.
Parameters:
routeTargetType
- the component type to display, notnull
parameters
- parameters for the target url.
-
rerouteTo
public void rerouteTo(String route)
Reroute to navigation component registered for given location string instead of the component about to be displayed.
This function doesn't change the browser URL as opposed to
forwardTo()
.Note that rerouting preserves the query parameters of the event.
Parameters:
route
- reroute target location string
-
rerouteTo
public <T> void rerouteTo(String route, T routeParam)
Reroute to navigation component registered for given location string with given route parameter instead of the component about to be displayed.
This function doesn't change the browser URL as opposed to
forwardTo()
.Note that rerouting preserves the query parameters of the event.
Type Parameters:
T
- route parameter typeParameters:
route
- reroute target location stringrouteParam
- route parameter
-
rerouteTo
public <T> void rerouteTo(String route, List<T> routeParams)
Reroute to navigation component registered for given location string with given route parameters instead of the component about to be displayed.
This function doesn't change the browser URL as opposed to
forwardTo()
.Note that rerouting preserves the query parameters of the event.
Type Parameters:
T
- route parameters typeParameters:
route
- reroute target location stringrouteParams
- route parameters
-
getForwardTargetType
public Class<? extends Component> getForwardTargetType()
Get the forward target type for forwarding.
Returns:
forward target type
Throws:
NullPointerException
- if no forward target is set. CheckhasForwardTarget()
before accessing this method.
-
getForwardTargetParameters
@Deprecated public List<String> getForwardTargetParameters()
Deprecated. use
getForwardTargetRouteParameters()
instead.Gets the URL parameters of the forward target.
Returns:
URL parameters of forward target
Throws:
NullPointerException
- if no forward target is set. CheckhasForwardTarget()
before accessing this method.
-
getForwardTargetRouteParameters
public RouteParameters getForwardTargetRouteParameters()
Gets the URL parameters of the forward target.
Returns:
URL parameters of forward target
Throws:
NullPointerException
- if no forward target is set. CheckhasForwardTarget()
before accessing this method.
-
getForwardUrl
public String getForwardUrl()
Gets the reroute url.
Returns:
the reroute url.
Throws:
NullPointerException
- if no forward target is set. CheckhasForwardTarget()
before accessing this method.
-
getRouteTargetType
@Deprecated public Class<? extends Component> getRouteTargetType()
Deprecated. use
getRerouteTargetType()
instead.Get the route target type for rerouting.
Returns:
route target type
-
getRerouteTargetType
public Class<? extends Component> getRerouteTargetType()
Get the route target type for rerouting.
Returns:
route target type
Throws:
NullPointerException
- if no reroute target is set. CheckhasRerouteTarget()
before accessing this method.
-
getRerouteTargetParameters
@Deprecated public List<String> getRerouteTargetParameters()
Deprecated. use
getRerouteTargetRouteParameters()
instead.Get the URL parameters of the reroute target.
Returns:
URL parameters of reroute target
Throws:
NullPointerException
- if no reroute target is set. CheckhasRerouteTarget()
before accessing this method.
-
getRerouteTargetRouteParameters
public RouteParameters getRerouteTargetRouteParameters()
Get the URL parameters of the reroute target.
Returns:
URL parameters of reroute target
Throws:
NullPointerException
- if no reroute target is set. CheckhasRerouteTarget()
before accessing this method.
-
getRerouteUrl
public String getRerouteUrl()
Gets the reroute url.
Returns:
the reroute url.
Throws:
NullPointerException
- if no reroute target is set. CheckhasRerouteTarget()
before accessing this method.
-
getNavigationTarget
public Class<?> getNavigationTarget()
Get the navigation target.
Returns:
navigation target
-
getRouteParameters
public RouteParameters getRouteParameters()
Gets the route parameters associated with this event.
Returns:
route parameters retrieved from the navigation url.
-
getLayouts
public List<Class<? extends RouterLayout>> getLayouts()
Get the layout chain for the
navigation target
.Returns:
layout chain
-
rerouteToError
public void rerouteToError(Class<? extends Exception> exception)
Reroute to error target for given exception without custom message.
Exception class needs to have default no-arg constructor.
Parameters:
exception
- exception to get error target forSee Also:
-
rerouteToError
public void rerouteToError(Class<? extends Exception> exception, String customMessage)
Reroute to error target for given exception with given custom message.
Exception class needs to have default no-arg constructor.
Parameters:
exception
- exception to get error target forcustomMessage
- custom message to send to error targetSee Also:
-
rerouteToError
public void rerouteToError(Exception exception, String customMessage)
Reroute to error target for given exception with given custom message.
Parameters:
exception
- exception to get error target forcustomMessage
- custom message to send to error target
-
hasErrorParameter
public boolean hasErrorParameter()
Check if we have an error parameter set for this navigation event.
Returns:
true if error parameter is set
-
getErrorParameter
public ErrorParameter<?> getErrorParameter()
Get the set error parameter.
Returns:
error parameter
-
getUI
public UI getUI()
Gets the UI this navigation takes place inside.
Returns:
the related UI instance
-
-