org.omnifaces.EXCEPTION_TYPES_TO_UNWRAP 不适用于非 ajax 请求
org.omnifaces.EXCEPTION_TYPES_TO_UNWRAP doesn't work for non-ajax requests
我使用 FullAjaxExceptionHandlerFactory
来处理 ajax 和非 ajax 请求期间的异常。
The FullAjaxExceptionHandler
will transparently handle exceptions during ajax requests exactly the same way as exceptions during synchronous (non-ajax) requests.
我注意到,如果在同步请求期间发生异常,findExceptionRootCause
(实际执行解包的方法)不会被调用。因此,web.xml
中定义的规则未被应用,因为它们依赖于 FullAjaxExceptionHandler
展开。
这是否意味着我需要扩展 FullAjaxExceptionHandler
还是我遗漏了什么?
堆栈跟踪:
(非ajax请求)
javax.servlet.ServletException:
Caused by: javax.faces.view.facelets.TagAttributeException
Caused by: javax.el.ELException
Caused by: xxx.MyException
web.xml:
<context-param>
<param-name>org.omnifaces.EXCEPTION_TYPES_TO_UNWRAP</param-name>
<param-value>javax.servlet.ServletException,javax.faces.view.facelets.TagAttributeException,javax.el.ELException</param-value>
</context-param>
...
<error-page>
<exception-type>xxx.MyException</exception-type>
<location>/xxx/page-not-found.xhtml</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/xxx/internal-server-error.xhtml</location>
</error-page>
*我记得 ELException
可以省略,因为它无论如何都会被包含在内。为了确定起见,我在堆栈跟踪中包含了异常之前的每种类型。
结果:
/xxx/internal-server-error.xhtml
显示
预计:
/xxx/page-not-found.xhtml
显示
更新:
对于上面提到的异常,如果我定义<error-page>
like
<error-page>
<exception-type>javax.faces.view.facelets.TagAttributeException</exception-type>
<location>/blueglue/templates/error/page-not-found.xhtml</location>
</error-page>
或
<error-page>
<exception-type>javax.servlet.ServletException</exception-type>
<location>/blueglue/templates/error/page-not-found.xhtml</location>
</error-page>
我会得到预期的结果 - 404 页面。
对于 javax.el.ELException
和 xxx.MyException
,异常导致 500 页,这不是我所期望的。
I use FullAjaxExceptionHandler
to handle exceptions during both ajax and non-ajax requests.
FullAjaxExceptionHandler
不会处理非ajax请求期间的异常。它的唯一目的是在 ajax 请求 期间以与非 ajax 请求相同的方式 处理异常(即显示在 web.xml
中定义的错误页面).
在您链接的展示页面中,您可以找到此部分:
Normal requests
Note that the FullAjaxExceptionHandler
does not deal with normal (non-ajax) requests at all. To properly handle JSF and EL exceptions on normal requests as well, you need an additional FacesExceptionFilter
. This will extract the root cause from a wrapped FacesException
and ELException
before delegating the ServletException
further to the container (the container will namely use the first root cause of ServletException
to match an error page by exception in web.xml
).
因此,您需要做的就是安装 FacesExceptionFilter
以获得与 FullAjaxExceptionHandler
相同的展开行为。
我使用 FullAjaxExceptionHandlerFactory
来处理 ajax 和非 ajax 请求期间的异常。
The
FullAjaxExceptionHandler
will transparently handle exceptions during ajax requests exactly the same way as exceptions during synchronous (non-ajax) requests.
我注意到,如果在同步请求期间发生异常,findExceptionRootCause
(实际执行解包的方法)不会被调用。因此,web.xml
中定义的规则未被应用,因为它们依赖于 FullAjaxExceptionHandler
展开。
这是否意味着我需要扩展 FullAjaxExceptionHandler
还是我遗漏了什么?
堆栈跟踪:
(非ajax请求)
javax.servlet.ServletException:
Caused by: javax.faces.view.facelets.TagAttributeException
Caused by: javax.el.ELException
Caused by: xxx.MyException
web.xml:
<context-param>
<param-name>org.omnifaces.EXCEPTION_TYPES_TO_UNWRAP</param-name>
<param-value>javax.servlet.ServletException,javax.faces.view.facelets.TagAttributeException,javax.el.ELException</param-value>
</context-param>
...
<error-page>
<exception-type>xxx.MyException</exception-type>
<location>/xxx/page-not-found.xhtml</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/xxx/internal-server-error.xhtml</location>
</error-page>
*我记得 ELException
可以省略,因为它无论如何都会被包含在内。为了确定起见,我在堆栈跟踪中包含了异常之前的每种类型。
结果:
/xxx/internal-server-error.xhtml
显示
预计:
/xxx/page-not-found.xhtml
显示
更新:
对于上面提到的异常,如果我定义<error-page>
like
<error-page>
<exception-type>javax.faces.view.facelets.TagAttributeException</exception-type>
<location>/blueglue/templates/error/page-not-found.xhtml</location>
</error-page>
或
<error-page>
<exception-type>javax.servlet.ServletException</exception-type>
<location>/blueglue/templates/error/page-not-found.xhtml</location>
</error-page>
我会得到预期的结果 - 404 页面。
对于 javax.el.ELException
和 xxx.MyException
,异常导致 500 页,这不是我所期望的。
I use
FullAjaxExceptionHandler
to handle exceptions during both ajax and non-ajax requests.
FullAjaxExceptionHandler
不会处理非ajax请求期间的异常。它的唯一目的是在 ajax 请求 期间以与非 ajax 请求相同的方式 处理异常(即显示在 web.xml
中定义的错误页面).
在您链接的展示页面中,您可以找到此部分:
Normal requests
Note that the
FullAjaxExceptionHandler
does not deal with normal (non-ajax) requests at all. To properly handle JSF and EL exceptions on normal requests as well, you need an additionalFacesExceptionFilter
. This will extract the root cause from a wrappedFacesException
andELException
before delegating theServletException
further to the container (the container will namely use the first root cause ofServletException
to match an error page by exception inweb.xml
).
因此,您需要做的就是安装 FacesExceptionFilter
以获得与 FullAjaxExceptionHandler
相同的展开行为。