重定向到<error-page>配置(HTTP 500)</error-page>的异常

时间:2014-09-18 13:35:12

标签: jsf-2 omnifaces

重定向到web.xml(HTTP 500)中配置的错误页面时遇到问题。 抛出以下异常

java.lang.NullPointerException at java.lang.StringBuilder.<init>(StringBuilder.java:77) 
at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.getRenderedViewId(FaceletViewDeclarationLanguage.java:1674)
FullAjaxExceptionHandler: Well, another exception occurred during rendering error page 'comum/paginas/erro/erro500.xhtml'. Trying to render a hardcoded error page now.

的web.xml

<error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>comum/paginas/erro/sessaoExpirada.xhtml</location>
</error-page>
<error-page>
    <exception-type>java.lang.Throwable</exception-type>
    <location>comum/paginas/erro/erro500.xhtml</location>
</error-page>
<error-page>
    <error-code>500</error-code>
    <location>comum/paginas/erro/erro500.xhtml</location>
</error-page>
<error-page>
    <error-code>403</error-code>
    <location>comum/paginas/erro/erro403.xhtml</location>
</error-page>
<error-page>
    <error-code>404</error-code>
    <location>comum/paginas/erro/erro404.xhtml</location>
</error-page>

在faces-config.xml中配置了FullAjaxExceptionHandlerFactory。

<factory>
    <exception-handler-factory>org.omnifaces.exceptionhandler.FullAjaxExceptionHandlerFactory</exception-handler-factory>
</factory>

我的facelets组件打包在一个jar文件中(/ META-INF / resources / comum / paginas / erro)。 ResourceResolver

<context-param>
    <param-name>javax.faces.FACELETS_RESOURCE_RESOLVER</param-name>
    <param-value>company.FaceletsResourceResolver</param-value>
</context-param>

public class FaceletsResourceResolver extends ResourceResolver {

    private ResourceResolver parent;
    private String basePath;

    public FaceletsResourceResolver(ResourceResolver parent) {
        this.parent = parent;
        this.basePath = "/META-INF/resources";
    }

    @Override
    public URL resolveUrl(String path) {
        URL url = parent.resolveUrl(path); // Resolves from WAR.
        if (url == null) {
            url = getClass().getResource(basePath + path); // Resolves from JAR.
        }
        return url;
    }
}

当facelets组件未打包在jar中时,重定向工作正常。 其他错误页面(403,404,sessionExpired)可以正常工作。 只有HTTP 500错误才会出现此错误。

环境:

  • Websphere 8.5.5.2
  • JSF 2.0(myfaces)
  • Primefaces 5.0
  • Omnifaces 1.7

1 个答案:

答案 0 :(得分:1)

<location>需要以/开头。

所以,例如。

<location>comum/paginas/erro/erro500.xhtml</location>

必须是

<location>/comum/paginas/erro/erro500.xhtml</location>