Details
Description
The standard Servlet mechanism for handling server-side exceptions is to specify an error-page entry in the web.xml file and allow the container to redirect to the configured resource. For example:
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/faces/viewExpired.xhtml</location>
</error-page>
This works fine as long as the exception makes it up to the servlet container. If the exception is handled in some other way where it doesn't bubble up to the container, then this mechanism is not effective.
For JSF 2, there is way to provide your own hook for exception handling. This is done using an ExceptionHandlerFactory and one or more custom ExceptionHandlers. By default, Mojarra provides implementations of both a standard ExceptionHandler for normal requests as well as an Ajax implementation for Ajax requests. Ajax requests in particular are bundled up as Ajax responses and sent back to the client without bubbling up the container so the error-page mechanism is bypassed.
We can potentially add value to ICEfaces by providing customized exception handling, particularly for Ajax requests. ExceptionHandlers are request-scoped resources (a new one for each request). The basic mechanism is to create an ExceptionHandlerFactory that links into the chain of existing ExceptionHandlerFactories and then creates an ExceptionHandler passing in the ExceptionHandler for wrapping. For example:
package org.icefaces.context;
import javax.faces.context.ExceptionHandler;
import javax.faces.context.ExceptionHandlerFactory;
public class ExceptionHandlerFactoryImpl extends ExceptionHandlerFactory {
ExceptionHandlerFactory delegateFactory;
public ExceptionHandlerFactoryImpl(ExceptionHandlerFactory delegateFactory) {
this.delegateFactory = delegateFactory;
}
public ExceptionHandler getExceptionHandler() {
return new MyExceptionHandler(delegateFactory.getExceptionHandler());
}
}
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/faces/viewExpired.xhtml</location>
</error-page>
This works fine as long as the exception makes it up to the servlet container. If the exception is handled in some other way where it doesn't bubble up to the container, then this mechanism is not effective.
For JSF 2, there is way to provide your own hook for exception handling. This is done using an ExceptionHandlerFactory and one or more custom ExceptionHandlers. By default, Mojarra provides implementations of both a standard ExceptionHandler for normal requests as well as an Ajax implementation for Ajax requests. Ajax requests in particular are bundled up as Ajax responses and sent back to the client without bubbling up the container so the error-page mechanism is bypassed.
We can potentially add value to ICEfaces by providing customized exception handling, particularly for Ajax requests. ExceptionHandlers are request-scoped resources (a new one for each request). The basic mechanism is to create an ExceptionHandlerFactory that links into the chain of existing ExceptionHandlerFactories and then creates an ExceptionHandler passing in the ExceptionHandler for wrapping. For example:
package org.icefaces.context;
import javax.faces.context.ExceptionHandler;
import javax.faces.context.ExceptionHandlerFactory;
public class ExceptionHandlerFactoryImpl extends ExceptionHandlerFactory {
ExceptionHandlerFactory delegateFactory;
public ExceptionHandlerFactoryImpl(ExceptionHandlerFactory delegateFactory) {
this.delegateFactory = delegateFactory;
}
public ExceptionHandler getExceptionHandler() {
return new MyExceptionHandler(delegateFactory.getExceptionHandler());
}
}
Issue Links
- blocks
-
ICE-6005 Detect and implement session expiry notification
- Closed
Activity
- All
- Comments
- History
- Activity
- Remote Attachments
- Subversion
The custom ExceptionHandler (and factory) have been added. ViewExpiredExceptions that occur during the Restore View phase are now detected and turned into SessionExpiredExceptions. If ICEpush is available, the notifications are pushed out to all Windows related to the expired session.