Quantcast
Channel: OmniFaces & JSF Fans
Viewing all articles
Browse latest Browse all 74

JSF Navigation Tutorial - Programmatic Navigation

$
0
0
JSF provides the NavigationHandlerand ConfigurableNavigationHandlerAPIs that can be used for tasks such as accessing navigation cases, customizing navigation handlers, conditional navigations, and so on. It is good to know that, programmatically speaking, we can do the following:

1. Obtain access to navigation handler (NavigationHandler) using the following code:

FacesContext context = FacesContext.getCurrentInstance();
Application application = context.getApplication();
NavigationHandler nh = application.getNavigationHandler();

2.Invoke navigation case using NavigationHandleras follows:

nh.handleNavigation(context, fromAction, outcome);
nh.handleNavigation(context, fromAction, outcome, toFlowDocumentId);

3.Access the ConfigurableNavigationHandlerAPI using the following code:

ConfigurableNavigationHandler cnh = (ConfigurableNavigationHandler) FacesContext.
getCurrentInstance().getApplication().getNavigationHandler();

4.Invoke navigation case using ConfigurableNavigationHandleras follows:

cnh.handleNavigation(context, fromAction, outcome);
cnh.handleNavigation(context, fromAction, outcome, toFlowDocumentId);

5.Retrieve one NavigationCase object by the action expression signature and outcome as shown in the following code:

NavigationCase case = cnh.getNavigationCase(context, fromAction, outcome);
NavigationCase case = cnh.getNavigationCase(context, fromAction, outcome, toFlowDocumentId);

6. Access all navigation rules into Map<String, Set<NavigationCase>>, where the keys are the <from-view-id/>values as follows:

Map<String, Set<NavigationCase>> cases = cnh.getNavigationCases();

Starting with JSF 2.2, we have wrappers for many classes that provide basic implementations and help developers to extend those classes and override only the necessary methods. Among them, we have a wrapper class for NavigationHandler, named NavigationHandlerWrapper, one for ConfigurableNavigationHandler, named ConfigurableNavigationHandlerWrapper, and one for NavigationCase, named NavigationCaseWrapper.

Viewing all articles
Browse latest Browse all 74

Trending Articles