My question is quite simple (to ask). How can I create and manage my Exceptions in a JSF application?
First we have the separation from normal and Ajax requests. Problem solved by using FullAjaxExceptionHandler by Omnifaces.
Ok, now my Ajax exceptions follow the JSF/web.xml
path. Next step is to create the mappings in web.xml
:
<error-page>
<exception-type>java.lang.SecurityException</exception-type>
<location>/errors/security.xhtml</location>
</error-page>
The problem then is that Exceptions are not going to match above rules as they have been wrapped by other Exception types. Ok, Omnifaces to the rescue again with FacesExceptionFilter.
Ok, so now I can throw Exceptions from my beans, e.g.
@PostConstruct
public void init() {
throw new SecurityException("Go away!");
}
Unfortunately this won't work, because Exception is thrown during bean initialization and not when calling a method.
Omnifaces unwrap
method will stop to the occurrence of aFacesException
and CDI (Weld) will wrap any exceptions during Bean
initialization to a FacesException (which I assume is conforming to the spec).
I could write my own Exception filter that will not stop unwrapping a FacesException
, you quickly realize that you might go deeper in the stacktrace than one would like.
How can I manage Exceptions during Bean
initialization?