This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FacesServlet Wrapper

 
massimo tarantelli
Ranch Hand
Posts: 35
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18014
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
massimo tarantelli
Ranch Hand
Posts: 35
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for the explanation, it was very useful..
Ciao
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic