This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "FacesServlet Wrapper" Watch "FacesServlet Wrapper" New topic

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?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15958

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..
Don't get me started about those stupid light bulbs.
subject: FacesServlet Wrapper
Similar Threads
How retrieve session value inside servlet
Custom input validator
Error message: Cannot forward after response has been commited
looking for feedback on servlet design
how to trigger a servlet from JSF