Error setting up error page in jsf?

In my project, I need to display an error page when certain errors occur in my code.
I added the following script in my header.xhtml page. This page is added to each page. Therefore, whenever an error occurs, I want to display the error page.

<script type="text/javascript"> A4J.AJAX.onExpired = function(loc, expiredMsg) { window.location = "../facelets/error/invalidSessionLogin.jsf"; }; A4J.AJAX.onError = function(req, status, message) { window.location = "../facelets/error/ajaxError.jsf"; }; </script> 

but it does not work.
And I also configure for error 500404 in web.xml. The code is as follows.

  <context-param> <description>Use this to suppress Facelets error page</description> <param-name>org.apache.myfaces.ERROR_HANDLING</param-name> <param-value>false</param-value> </context-param> <error-page> <error-code>500</error-code> <location>/facelets/error/internalErrorHome.jsf</location> </error-page> <!-- if required page not available --> <error-page> <error-code>404</error-code> <location>/facelets/error/pageNotFoundErrorHome.jsf</location> </error-page> 

But that gives me the following error.

 11:41:30,618 ERROR [[localhost]] Exception Processing ErrorPage[errorCode=404, location=/facelets/error/pageNotFoundErrorHome.jsf] com.sun.faces.context.FacesFileNotFoundException: /facelets/error/pageNotFoundErrorHome.xhtml Not Found in ExternalContext as a Resource 

I do not know where I will be wrong. I am not getting an error not found in ExternalContext as a resource

+4
source share
2 answers
  • You should check if the path you mentioned is accessible or not, and first correct the paths if they don't work.

  • Why don't you create a navigation case for these error codes, and then instead of using relative paths, set the appropriate URLs.

    window.location = "$ {request.contextpath} / error / 404";

Consider, for example:

  mywebapp | |---WEB-INF | |---error | | | |---404.xhtml (and so on) 

In web.xml:

  <error-page> <error-code>404</error-code> <location>/error/404.xhtml</location> </error-page> 

and similarly for a 500 error code.

+6
source

AFAIK, you cannot register a JSF page as an error page in web.xml. Instead, you should use JSP.

 <error-page> <error-code>404</error-code> <location>/error404.jsp</location> </error-page> 
-1
source

Source: https://habr.com/ru/post/1485930/


All Articles