Preemptive navigation is a new feature in JavaServer Faces 2.0 and allows runtime introspection of control flow cases for their target view.The JSF API for this is the ConfigurableNavigationHander class that exposes the following methods
Also note that Preemptive navigation fails with a NullPointer exception if the referenced control flow case is conditionally set to disabled. To handle this, the managed bean code above needs to be surrounded with a try…catch block.
getNavigationCase(FacesContext context, java.lang.String fromAction, java.lang.String outcome)
- getNavigationCases() – returns a
Map<String, Set<NavigationCase>>that lists all available navigation cases with the viewId as the map keys
- performNavigation(java.lang.String outcome) – Navigates to the next view based on the outcome. Developers using this method must ensure it is used during JSF InvokeApplication phase as it cannot be used any later
The NavigationCase class wraps the information defined for a navigation, including the condition (also a new feature in JSF 2.0) in which the navigation case is valid.
Preemptive navigation can be used in an application to populate redirect components, like the goLink shown below with a target view, or for redirects in a managed bean, for which developers need to know the target view. The sample below shows an ADF Faces goLink pointing to a managed bean. The managed bean returns the redirect URL for the link to follow when clicked on.
The managed bean accesses the NavigationHandler defined for the JSF instance and verifies it to be an instance of ConfigurableNavigationHandler before it looks up the target viewId for the control flow case.
Note that ADFc in Oracle JDeveloper 11g R2 also supports conditional navigation, in which case developers can define an EL expression on the control flow case, using the Property Inspector, that determines when a navigation case is valid and when it is not.