A great feature of JSF 2.0 is focused on the navigation mechanism. Until JSF 2.0 the navigation cases mapped into faces-config.xml
were fixed and once the application was deployed this file could not be altered, therefore its content was not flexible. That is no longer the case in JSF 2.0, because a new navigation handler interface, named ConfigurableNavigationhandler
, has been introduced. It allows us to query and make live modifications to the registered NavigationCase
objects. This is the subject of our last recipe in this chapter.
At JSF startup the navigation cases are extracted from the descriptor and registered with the ConfigurableNavigationHandler
(of course, they are also put into NavigationCase
objects). A NavigationCase
object can be retrieved by the action expression signature and logical outcome under which it is registered:
… NavigationCase navigationCase = navigationHandler.getNavigationCase(facesContext, "#{…}", "…"); …
In addition, you can retrieve the complete navigation set as a Map<String, Set<NavigationCase>>
. The keys are the <from-view-id>
tag values (notice that you can use the extracted map to register your own navigation cases dynamically—once you can control a NavigationCase
you can dynamically control flow):
… Map<String, Set<NavigationCase>> ns = navigationHandler.getNavigationCases(); …
To obtain a ConfigurableNavigationHandler
object you need to apply a cast conversion as shown:
… ConfigurableNavigationHandler configurableNavigationHandler = (ConfigurableNavigationHandler)FacesContext. getCurrentInstance().getApplication().getNavigationHandler(); …