2
votes

I'm having problems when redirecting to error-page configured in web.xml (HTTP 500). The following exception is being thrown

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>

FullAjaxExceptionHandlerFactory was configured in faces-config.xml.

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

My facelets components are packaged in a jar file (/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;
    }
}

When facelets components were not packaged in a jar, the redirect worked properly. The other error pages (403, 404, sessionExpired) work without problems. The error only occurs with the HTTP 500 error.

Environment:

  • Websphere 8.5.5.2
  • JSF 2.0 (myfaces)
  • Primefaces 5.0
  • Omnifaces 1.7
1
"Well, another exception occurred during rendering error page 'comum/paginas/erro/erro500.xhtml'." seems pretty clear; your erro500.xhtml file cannot be rendered apparently and so probably contains a mistake. Looks like a typo too, I would expect the file to be named error500.xhtml. - Gimby
"erro" is Portuguese for "error". - BalusC
@Gimby it's not a typo error, "erro" is brazilian portuguese. - gfinotti

1 Answers

2
votes

The <location> needs to start with /.

So e.g.

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

must be

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