HTML and CSS Reference
In-Depth Information
Ti It is important to know that the <to-view-id> can take a JSF eL expression that would be evaluated by the JSF
navigation handler in order to obtain the view identifier.
Behind the scenes, the JSF navigation is handled by the NavigationHandler class. If a navigation case is
matched by the NavigationHandler class, it will change the current view by making a call to the FacesContext.
setViewRoot(UIViewRoot) API with the new view. It is useful to know how to work with the NavigationHandler class,
because you may have to work with it directly from many places in your JSF application (such as phase listeners and
exception handlers [there is an example for this one in the “Exception Handling” section]). Listing 2-36 shows an
example of using the NavigationHandler .
Listing 2-36. An Example of Using the NavigationHandler Class
FacesContext context = FacesContext.getCurrentInstance();
NavigationHandler navigationHandler = context.getApplication().getNavigationHandler();
navigationHandler.handleNavigation(context, "#{myBean.handleFlow1}", "flow1");
The NavigationHandler class has a handleNavigation method with the following parameters:
context : Represents the current JSF FacesContext .
fromAction : A String that represents an action method expression ( "#{myBean.
handleFlow1}" ) that produced the specified outcome. It can be null .
outcome : A String that represents the outcome ( "flow1" ). It can be null .
Not When the outcome of a specific action is null , the NavigationHandler does nothing, which means that the
current view will be redisplayed.
Exception Handling
Exception handling is one of the most important concerns that have to be taken care of in the Java EE web application.
Exception handling has many benefits: it can display friendly messages for the application end users when an
application error raises, which increases the trust of using the application from the end-user point of view; adding to
this, exception handling allows application developers to easily troubleshoot and debug application defects. Since
JSF 2.0, an exception handling mechanism is supported by the framework in order to have a centralized place for
handling exceptions in the JSF applications.
Let's create a custom JSF exception handler to the firstApplication in order to understand how to handle
exceptions in the JSF applications. In order to create a custom exception handler for the JSF application, we need to
do three things:
Creating a custom exception handler class which handles the application exceptions.
This handler class should extend an exception handling wrapper class (such as the
ExceptionHandlerWrapper class).
Creating a custom exception handler factory class which is responsible for creating the
instances of the exception handler class. The custom exception handler class should extend
the JSF ExceptionHandlerFactory class.
Search WWH ::

Custom Search