title: Error pages for exceptions during page rendering
body: <p>In the backing beans of my JSF application, certain exceptions may be thrown at any time, and I want to react to this by redirecting to an error page. I have included the <a href="http://omnifaces.org" rel="nofollow">omnifaces</a> FullAjaxExceptionHandler, and my <code>web.xml</code> contains</p>
  
  <pre><code>&lt;error-page&gt;
      &lt;exception-type&gt;my.own.ResourceNotFoundException&lt;/exception-type&gt;
      &lt;location&gt;/error/error404.xhtml&lt;/location&gt;
  &lt;/error-page&gt;
  &lt;error-page&gt;
      &lt;error-code&gt;500&lt;/error-code&gt;
      &lt;location&gt;/error/error500.xhtml&lt;/location&gt;
  &lt;/error-page&gt;
  </code></pre>
  
  <p>In most cases, including Ajax requests, this works fine: <code>ResourceNotFoundException</code> leads me to the error page. However, when the exception is thrown in a method annotaded with <code>@PostConstruct</code>, I always get the generic page for error code 500.</p>
  
  <p>Is this because JSF wraps the exception in something else and the mechanism in <code>web.xml</code> does not recognize it? If yes, how can I get this to work as expected?</p>
  
  <p>Here is the exception trace I see in the server log:</p>
  
  <pre><code>    Feb 07, 2013 11:08:32 AM com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
  SEVERE: Error Rendering View[/my/projects/details/details.xhtml]
  javax.el.ELException: //P:/codebase/code/portal/jsf-impl/target/classes/META-INF/resources/common/title.xhtml: Bei der Ressourcen-Einspeisung auf dem verwalteten Bean projectDetailsController ist ein Fehler aufgetreten.
      at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:90)
      at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
      at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:302)
      at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:309)
      at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:105)
      at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
      at com.sun.faces.renderkit.html_basic.CompositeRenderer.encodeChildren(CompositeRenderer.java:78)
      at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
      at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402)
      at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
      at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
      at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
      at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at my.own.filters.SecurityFilter.doFilter(SecurityFilter.java:48)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
      at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:185)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      at org.apache.catalina.core.StandardHostValve.__invoke(StandardHostValve.java:151)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
      at my.own.UTF8Valve.invoke(UTF8Valve.java:34)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:269)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
      at java.lang.Thread.run(Thread.java:722)
  Caused by: com.sun.faces.mgbean.ManagedBeanCreationException: Bei der Ressourcen-Einspeisung auf dem verwalteten Bean projectDetailsController ist ein Fehler aufgetreten.
      at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:229)
      at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:105)
      at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
      at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
      at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
      at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
      at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
      at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
      at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:71)
      at org.apache.el.parser.AstValue.getValue(AstValue.java:147)
      at org.apache.el.parser.AstDeferredExpression.getValue(AstDeferredExpression.java:44)
      at org.apache.el.parser.AstCompositeExpression.getValue(AstCompositeExpression.java:50)
      at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
      at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
      at javax.faces.component.UIComponentBase$AttributesMap.get(UIComponentBase.java:2362)
      at com.sun.faces.el.CompositeComponentAttributesELResolver$ExpressionEvalMap.get(CompositeComponentAttributesELResolver.java:345)
      at javax.el.MapELResolver.getValue(MapELResolver.java:52)
      at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
      at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
      at org.apache.el.parser.AstValue.getValue(AstValue.java:169)
      at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
      at com.sun.faces.facelets.el.ELText$ELTextVariable.writeText(ELText.java:227)
      at com.sun.faces.facelets.el.ELText$ELTextComposite.writeText(ELText.java:150)
      at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:85)
      ... 43 more
  Caused by: com.sun.faces.spi.InjectionProviderException
      at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:119)
      at com.sun.faces.vendor.WebContainerInjectionProvider.invokePostConstruct(WebContainerInjectionProvider.java:99)
      at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:223)
      ... 66 more
  Caused by: java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:117)
      ... 68 more
  Caused by: my.own.ResourceNotFoundException: Did not find project
      at my.own.projects.details.ProjectDetailsController.createModel(ProjectDetailsController.java:198)
  </code></pre>