HTML and CSS Reference
In-Depth Information
fc.renderResponse();
} finally {
i.remove();
}
}
// Call the parent exception handler's handle() method
getWrapped().handle();
}
}
The core method of the CustomExceptionHandler class is the handle() method, which is responsible for handling
the exceptions in the JSF application. It is important to note that the getUnhandledExceptionQueuedEvents()
method can be used for getting all of the unhandled exceptions in the JSF application. Every item in the returned
Iterable object represents an ExceptionQueuedEvent object. From the ExceptionQueuedEvent object, you can get the
ExceptionQueuedEventContext object, from which you can retrieve the Throwable object. Using the Throwable object,
you can verify the exceptions you want to handle in the applications. Finally, the NavigationHandler is used in order
to navigate to the application error page ( error.xhtml ), and the ExceptionQueuedEvent is removed from the Iterable
object. Listing 2-38 shows the error.xhtml page.
Listing 2-38. The Application Error Page
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns=" http://www.w3.org/1999/xhtml "
xmlns:h=" http://java.sun.com/jsf/html " >
<h:head>
<title>Error</title>
<link href="#{request.contextPath}/css/simple.css" rel="stylesheet" type="text/css"/>
</h:head>
<h:body>
<h2 class="errorMessage">
An error occurs. return to <a href="index.xhtml">login</a> page.
</h2>
</h:body>
</html>
Secondly, we need to create the custom exception handler factory class that is responsible for creating the
instances of the CustomExceptionHandler class. Listing 2-39 shows the CustomExceptionHandlerFactory class.
Listing 2-39. The CustomExceptionHandlerFactory Class
package com.jsfprohtml5.firstapplication.exceptions;
import javax.faces.context.ExceptionHandler;
import javax.faces.context.ExceptionHandlerFactory;
public class CustomExceptionHandlerFactory extends ExceptionHandlerFactory {
private ExceptionHandlerFactory parent;
 
Search WWH ::




Custom Search