jsf - 处理模板评估期间发生的域异常

标签 jsf omnifaces

我正在为特定的异常类型设计一个错误页面。

<error-page>
    <exception-type>xxx.AbstractConfigurableNotFoundException</exception-type>
    <location>/xxx/page-not-found.xhtml</location>
</error-page>

我正在使用 OmniFaces 及其异常工厂来处理错误。
<factory>
    <exception-handler-factory>org.omnifaces.exceptionhandler.FullAjaxExceptionHandler</exception-handler-factory>
</factory>
AbstractConfigurable是一个域类,它的实例是在模板评估期间创建的*。 AbstractConfigurable的构造函数可能会抛出 AbstractConfigurableNotFoundException .当它发生时,这个异常作为一个原因被包装到特定于模板的异常中。
javax.servlet.ServletException
    Caused by: javax.faces.view.facelets.TagAttributeException
         Caused by: com.sun.faces.mgbean.ManagedBeanCreationException
              ...
                   Caused by: xxx.AbstractConfigurableNotFoundException

结果,出现了不同的异常类型和我的 <error-page>逻辑不适用。

明明不想管,javax.faces.view.facelets.TagAttributeException
<error-page>
    <exception-type>javax.faces.view.facelets.TagAttributeException</exception-type>
    <location>/xxx/page-not-found.xhtml</location>
</error-page>

但我想用 AbstractConfigurableNotFoundException 处理任何异常作为一个原因。

有什么我可以做的吗?

最佳答案

FullAjaxExceptionHandler支持上下文参数来设置要解包的异常类型的完全限定名称。以下是其 documentation 的相关摘录:

Configuration

By default only FacesException and ELException are unwrapped. You can supply a context parameter "org.omnifaces.EXCEPTION_TYPES_TO_UNWRAP" to specify additional exception types to unwrap. The context parameter value must be a commaseparated string of fully qualified names of additional exception types. Note that this also covers subclasses of specified exception types.

<context-param>
    <param-name>org.omnifaces.EXCEPTION_TYPES_TO_UNWRAP</param-name>
    <param-value>javax.ejb.EJBException,javax.persistence.RollbackException</param-value>
</context-param>

This context parameter will also be read and used by FacesExceptionFilter.



因此,在您的特定情况下,您可以在 web.xml 中使用以下配置:
<context-param>
    <param-name>org.omnifaces.EXCEPTION_TYPES_TO_UNWRAP</param-name>
    <param-value>com.sun.faces.mgbean.ManagedBeanCreationException</param-value>
</context-param>

请注意 javax.faces.view.facelets.TagAttributeException延伸自 FacesException ,默认情况下已经解包,所以你真的不需要指定它。

关于jsf - 处理模板评估期间发生的域异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57143407/

相关文章:

jsf - 使用 FullAjaxExceptionHandler 时出现 StringIndexOutOfBoundsException

validation - 将参数传递给 o :validateOrder OmniFaces 2. 0 中的资源文件

jsf - EL 调用 remove(int i) 而不是 remove(Object o)

javascript - 从 java 文件中的函数弹出简单的文本消息警报

jsf - 从 primefaces 数据表导出的 Excel 文件中不显示标题

java - JSF/Primefaces - JAR 和 Spring 中的 XHTML

jsf - 不会调用 OmniFaces FullAjaxExceptionHandler 的 logException 方法重写

jsf - “omnifaces.SelectItemsConverter”转换器 ID 未注册

java - Tomcat 7 找不到我的类抛出 javax.el.E​​LException : java. lang.NoClassDefFoundError