Class NavigationEndedEvent
- All Implemented Interfaces:
Serializable
service event bus
when the server has finished handling a navigation for a UI, telling how it
ended.
It is always fired after the matching NavigationStartedEvent, on the
same thread, also when the navigation throws. A listener can therefore keep
timing state in a ThreadLocal. Both events are fired on the request
thread while the session is locked. The listeners of this event are called in
the reverse order of registration, so that they nest around the listeners of
the started event.
Only the outermost navigation is reported. A
forward, a
reroute, the redirect that adds or
removes a trailing slash and the rendering of an error view are part of the
navigation that caused them and fire no events of their own. Their effect is
in the outcome.
Two cases fire no events at all, since they continue a navigation that has
already been reported: resuming a postponed navigation with
BeforeLeaveEvent.ContinueNavigationAction.proceed(), and showing a
PreserveOnRefresh view once the browser has sent its window name, in
the request after the one reported as NavigationEndedEvent.NotShown.
Use a switch over the outcome to tell the cases apart:
String result = switch (event.getOutcome()) {
case Completed completed -> completed.navigationTarget().getSimpleName();
case Postponed postponed -> "postponed";
case Failed failed -> "failed: " + failed.error();
case NotShown notShown -> "no view shown";
};
- Since:
- 25.4
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe navigation showed a view.static final recordThe navigation failed.static final recordThe server finished handling the navigation without showing a view, and the view shown before is still in the UI.static interfaceHow a navigation ended.static final recordABeforeLeaveEventlistener of the current view postponed the navigation, so the current view is still shown. -
Field Summary
Fields inherited from class java.util.EventObject
source -
Constructor Summary
ConstructorsConstructorDescriptionNavigationEndedEvent(UI ui, Location location, NavigationTrigger trigger, NavigationEndedEvent.Outcome outcome, int statusCode) Creates a new event. -
Method Summary
Modifier and TypeMethodDescriptionGets the location that was requested, before any forward or reroute.Gets how the navigation ended.intGets the HTTP status code of the navigation, such as 200 for a view that was shown or 404 for the "not found" error view.Gets the action that triggered the navigation.getUI()Gets the UI that navigated.Methods inherited from class java.util.EventObject
getSource, toString
-
Constructor Details
-
Method Details
-
getUI
Gets the UI that navigated.- Returns:
- the UI, never
null
-
getLocation
Gets the location that was requested, before any forward or reroute. It is the same as in the matchingNavigationStartedEvent.- Returns:
- the requested location, never
null
-
getTrigger
Gets the action that triggered the navigation. It is the same as in the matchingNavigationStartedEvent.- Returns:
- the navigation trigger, never
null
-
getOutcome
Gets how the navigation ended.- Returns:
- the outcome, never
null
-
getStatusCode
public int getStatusCode()Gets the HTTP status code of the navigation, such as 200 for a view that was shown or 404 for the "not found" error view. On the initial page load it is the status code of the response. A navigation that throws has no status code, which is reported as-1.- Returns:
- the HTTP status code, or
-1if the navigation threw
-