Class BeforeEvent

java.lang.Object
java.util.EventObject
com.vaadin.flow.router.BeforeEvent
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
BeforeEnterEvent, BeforeLeaveEvent

public abstract class BeforeEvent extends EventObject
Abstract before event class that has the common functionalities for BeforeLeaveEvent and BeforeEnterEvent.
Since:
1.0
See Also:
  • Constructor Details

    • BeforeEvent

      public BeforeEvent(NavigationEvent event, Class<?> navigationTarget, List<Class<? extends RouterLayout>> layouts)
      Constructs event from a NavigationEvent.
      Parameters:
      event - NavigationEvent that is on-going, not null
      navigationTarget - navigation target, not null
      layouts - Navigation layout chain, not null
    • 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, not null
      navigationTarget - navigation target, not null
      parameters - route parameters, not null
      layouts - Navigation layout chain, not null
    • 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, not null
      trigger - the type of user action that triggered this location change, not null
      location - the new location, not null
      navigationTarget - navigation target class, not null
      ui - the UI related to the navigation, not null
      layouts - the layout chain for the navigation target, not null
    • 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, not null
      trigger - the type of user action that triggered this location change, not null
      location - the new location, not null
      navigationTarget - navigation target class, not null
      parameters - route parameters, not null
      ui - the UI related to the navigation, not null
      layouts - the layout chain for the navigation target, not null
  • Method Details

    • hasUnknownForward

      public boolean hasUnknownForward()
      Gets if forward route is unknown. This is true only when a forward route is not found using forwardTo(String) and forwardTo(String, QueryParameters) methods.
      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) and rerouteTo(String, QueryParameters) 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.
    • getExternalForwardUrl

      public String getExternalForwardUrl()
      Gets the external forward url.
      Returns:
      the external forward url or null if none has been set
    • 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 class EventObject
    • hasForwardTarget

      public boolean hasForwardTarget()
      Check if we have a forward target.
      Returns:
      forward target exists
    • hasExternalForwardUrl

      public boolean hasExternalForwardUrl()
      Check if we have a forward for an external URL.
      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, or null to clear a previously set forward target
      targetState - 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, not null
    • 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, not null
    • forwardTo

      public <T, C extends Component & HasUrlParameter<T>> void forwardTo(Class<? extends C> forwardTargetComponent, T routeParameter)
      Forward the navigation to show the given component with given route parameter 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.

      Type Parameters:
      T - route parameter type
      C - navigation target type
      Parameters:
      forwardTargetComponent - the component type to display, not null
      routeParameter - route parameter for the target
    • forwardTo

      public <T, C extends Component & HasUrlParameter<T>> void forwardTo(Class<? extends C> forwardTargetComponent, List<T> routeParameters)
      Forward the navigation to show the given component with given route parameters 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.

      Type Parameters:
      T - route parameters type
      C - navigation target type
      Parameters:
      forwardTargetComponent - the component type to display, not null
      routeParameters - route parameters for the target
    • forwardTo

      public void forwardTo(Class<? extends Component> forwardTargetComponent, RouteParameters parameters)
      Forward the navigation to show the given component with given route parameters 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, not null
      parameters - route parameters for the target
    • forwardTo

      public <T, C extends Component & HasUrlParameter<T>> void forwardTo(Class<? extends C> forwardTargetComponent, T routeParameter, QueryParameters queryParameters)
      Forward the navigation to show the given component with given route parameter and query parameters instead of the component that is currently about to be displayed.

      This function changes the browser URL as opposed to rerouteTo().

      Type Parameters:
      T - route parameter type
      C - navigation target type
      Parameters:
      forwardTargetComponent - the component type to display, not null
      routeParameter - route parameter for the target
      queryParameters - query parameters for the target
    • forwardTo

      public <C extends Component> void forwardTo(Class<? extends C> forwardTargetComponent, RouteParameters routeParameters, QueryParameters queryParameters)
      Forward the navigation to show the given component with given route parameters and query parameters instead of the component that is currently about to be displayed.

      This function changes the browser URL as opposed to rerouteTo().

      Type Parameters:
      C - navigation target type
      Parameters:
      forwardTargetComponent - the component type to display, not null
      routeParameters - route parameters for the target
      queryParameters - query parameters for the target
    • forwardTo

      public <C extends Component> void forwardTo(Class<? extends C> forwardTargetComponent, QueryParameters queryParameters)
      Forward the navigation to show the given component with given query parameters instead of the component that is currently about to be displayed.

      This function changes the browser URL as opposed to rerouteTo().

      Type Parameters:
      C - navigation target type
      Parameters:
      forwardTargetComponent - the component type to display, not null
      queryParameters - query parameters for the target
    • 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
    • forwardToUrl

      public void forwardToUrl(String externalForwardUrl)
      Forward to the given URL instead of the component about to be displayed.

      This function performs a page reload in the browser with the new URL.

      Parameters:
      externalForwardUrl - 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 type
      Parameters:
      location - forward target location string
      locationParam - 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 type
      Parameters:
      location - forward target location string
      locationParams - location parameters
    • forwardTo

      public void forwardTo(String locationString, QueryParameters queryParameters)
      Forward to navigation component registered for given location string with given query parameters instead of the component about to be displayed.

      This function changes the browser URL as opposed to rerouteTo().

      Parameters:
      locationString - forward target location string
      queryParameters - query parameters for the target
    • 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, or null to clear a previously set reroute target
      targetState - 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, not null
    • 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, not null
    • rerouteTo

      public <T, C extends Component & HasUrlParameter<T>> void rerouteTo(Class<? extends C> routeTargetType, T routeParameter)
      Reroutes the navigation to show the given component with given route parameter 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.

      Type Parameters:
      T - route parameter type
      C - navigation target type
      Parameters:
      routeTargetType - the component type to display, not null
      routeParameter - route parameter for the target
    • rerouteTo

      public <T, C extends Component & HasUrlParameter<T>> void rerouteTo(Class<? extends C> routeTargetType, List<T> routeParameters)
      Reroutes the navigation to show the given component with given route parameters 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.

      Type Parameters:
      T - route parameter type
      C - navigation target type
      Parameters:
      routeTargetType - the component type to display, not null
      routeParameters - route parameters for the target
    • rerouteTo

      public void rerouteTo(Class<? extends Component> routeTargetType, RouteParameters parameters)
      Reroutes the navigation to show the given component with given route parameters 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, not null
      parameters - parameters for the target url.
    • rerouteTo

      public <T, C extends Component & HasUrlParameter<T>> void rerouteTo(Class<? extends C> routeTargetType, T routeParameter, QueryParameters queryParameters)
      Reroutes the navigation to show the given component with given route parameter and query parameters instead of the component that is currently about to be displayed.

      This function doesn't change the browser URL as opposed to forwardTo().

      Type Parameters:
      T - route parameter type
      C - navigation target type
      Parameters:
      routeTargetType - the component type to display, not null
      routeParameter - route parameter for the target
      queryParameters - query parameters for the target
    • rerouteTo

      public <C extends Component> void rerouteTo(Class<? extends C> routeTargetType, RouteParameters routeParameters, QueryParameters queryParameters)
      Reroutes the navigation to show the given component with given route parameters and query parameters instead of the component that is currently about to be displayed.

      This function doesn't change the browser URL as opposed to forwardTo().

      Type Parameters:
      C - navigation target type
      Parameters:
      routeTargetType - the component type to display, not null
      routeParameters - route parameters for the target
      queryParameters - query parameters for the target
    • rerouteTo

      public <C extends Component> void rerouteTo(Class<? extends C> routeTargetType, QueryParameters queryParameters)
      Reroutes the navigation to show the given component with given query parameters instead of the component that is currently about to be displayed.

      This function doesn't change the browser URL as opposed to forwardTo().

      Type Parameters:
      C - navigation target type
      Parameters:
      routeTargetType - the component type to display, not null
      queryParameters - query parameters for the target
    • 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 type
      Parameters:
      route - reroute target location string
      routeParam - 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 type
      Parameters:
      route - reroute target location string
      routeParams - route parameters
    • rerouteTo

      public void rerouteTo(String route, QueryParameters queryParameters)
      Reroute to navigation component registered for given location string with given query parameters instead of the component about to be displayed.

      This function doesn't change the browser URL as opposed to forwardTo().

      Parameters:
      route - reroute target location string
      queryParameters - query parameters for the target
    • 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. Check hasForwardTarget() 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. Check hasForwardTarget() before accessing this method.
    • getForwardUrl

      public String getForwardUrl()
      Gets the reroute url.
      Returns:
      the reroute url.
      Throws:
      NullPointerException - if no forward target is set. Check hasForwardTarget() before accessing this method.
    • 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. Check hasRerouteTarget() 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. Check hasRerouteTarget() before accessing this method.
    • getRerouteUrl

      public String getRerouteUrl()
      Gets the reroute url.
      Returns:
      the reroute url.
      Throws:
      NullPointerException - if no reroute target is set. Check hasRerouteTarget() 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.
    • hasRedirectQueryParameters

      public boolean hasRedirectQueryParameters()
      Check if we have query parameters for forwarded and rerouted URL.
      Returns:
      query parameters exists
    • getRedirectQueryParameters

      public QueryParameters getRedirectQueryParameters()
      Gets the query parameters for forwarded and rerouted URL. null means that query parameters of the event are preserved in the forwarded and rerouted URL.
      Returns:
      query parameters for forwarding and rerouting
    • 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 for
      See 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 for
      customMessage - custom message to send to error target
      See 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 for
      customMessage - 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