File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes FacesServlet Wrapper Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "FacesServlet Wrapper" Watch "FacesServlet Wrapper" New topic
Author

FacesServlet Wrapper

massimo tarantelli
Ranch Hand

Joined: Jun 19, 2012
Posts: 35

Hello to everybody...first post in the forum that infact I follow since a long time ago...
i have a problem with a wrapper of the FacesServlet engine, that I had to build to catch an exception, here the code:



I don't undestain why it gives me a nullPointerException on the "FacesContext context = FacesContext.getCurrentInstance()".
Moreover, i tryed to build inside the catch block also a new webpage using the response, but when i call the method "response.getWriter();" an other IllegalStateException is thrown.
any suggestions?
thanks
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

Benvenuto, Massimo! Welcome to the JavaRanch.

You are doing something very peculiar, aggregating on the FacesServlet. Usually, one would subclass it, instead.

The FacesContext is not a construct that has an extended lifespan. It is created when a request comes in, used to process the request and create a response, and then discarded (destroyed) once the response has been sent back to the requester. So the reason your code fails is that the FacesContext has not yet been created.

In actual practice, altering the FacesServlet is not the best way to handle FacesExceptions. Ideally the application logic will intercept Exceptions before they get thrown upstream to the FacesServlet. When that is not possible, it is better to set error traps in the web.xml file.


Customer surveys are for companies who didn't pay proper attention to begin with.
massimo tarantelli
Ranch Hand

Joined: Jun 19, 2012
Posts: 35

Thanks a lot for the explanation, it was very useful..
Ciao
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FacesServlet Wrapper