public class FullAjaxExceptionHandler extends ExceptionHandlerWrapper
FullAjaxExceptionHandlerFactory
how to setup it.
This exception handler will parse the web.xml and web-fragment.xml files to find the error page
locations of the HTTP error code 500 and all declared specific exception types. Those locations need to
point to Facelets files. The location of the HTTP error code 500 or the exception type
java.lang.Throwable
is required in order to get the full ajax exception handler to work, because
there's then at least a fall back error page whenever there's no match with any of the declared specific exceptions.
So, you must at least have either
<error-page> <error-code>500</error-code> <location>/errors/500.xhtml</location> </error-page>
or
<error-page> <exception-type>java.lang.Throwable</exception-type> <location>/errors/500.xhtml</location> </error-page>
Both can also, only the java.lang.Throwable
one will always get precedence over the 500
one, as per the Servlet API specification, so the 500 one would be basically superfluous.
The exception detail is available in the request scope by the standard servlet error request attributes like as in a normal synchronous error page response. You could for example show them in the error page as follows:
<ul> <li>Date/time: #{of:formatDate(now, 'yyyy-MM-dd HH:mm:ss')}</li> <li>User agent: #{header['user-agent']}</li> <li>User IP: #{request.remoteAddr}</li> <li>Request URI: #{requestScope['javax.servlet.error.request_uri']}</li> <li>Ajax request: #{facesContext.partialViewContext.ajaxRequest ? 'Yes' : 'No'}</li> <li>Status code: #{requestScope['javax.servlet.error.status_code']}</li> <li>Exception type: #{requestScope['javax.servlet.error.exception_type']}</li> <li>Exception message: #{requestScope['javax.servlet.error.message']}</li> <li>Stack trace: <pre>#{of:printStackTrace(requestScope['javax.servlet.error.exception'])}</pre> </li> </ul>
Exceptions during render response can only be handled when the javax.faces.FACELETS_BUFFER_SIZE
is
large enough so that the so far rendered response until the occurrence of the exception fits in there and can
therefore safely be resetted.
FullAjaxExceptionHandlerFactory
Constructor and Description |
---|
FullAjaxExceptionHandler(ExceptionHandler wrapped)
Construct a new ajax exception handler around the given wrapped exception handler.
|
Modifier and Type | Method and Description |
---|---|
ExceptionHandler |
getWrapped() |
void |
handle()
Handle the ajax exception as follows, only and only if the current request is an ajax request with an uncommitted
response and there is at least one unhandled exception:
If the exception is an instance of
FacesException , then unwrap its root cause as long as it is not
an instance of FacesException . |
getHandledExceptionQueuedEvent, getHandledExceptionQueuedEvents, getRootCause, getUnhandledExceptionQueuedEvents, isListenerForSource, processEvent
public FullAjaxExceptionHandler(ExceptionHandler wrapped)
wrapped
- The wrapped exception handler.public void handle() throws FacesException
FacesException
, then unwrap its root cause as long as it is not
an instance of FacesException
.
WebXml.findErrorPageLocation(Throwable)
.
handle
in class ExceptionHandlerWrapper
FacesException
public ExceptionHandler getWrapped()
getWrapped
in interface FacesWrapper<ExceptionHandler>
getWrapped
in class ExceptionHandlerWrapper