JSF 2 and navigation cases

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.

How to do it...

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();
…

How it works...

In principle, the new JSF 2.0 API allows us to have complete control over navigation cases. This feature allows us to dynamically control the application flow and once you get an instance of ConfigurableNavigationHandler you can define the navigation model or use it to generate bookmarkable URLs.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset