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 How to get FacesContext.getCurrentInstance() from a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "How to get FacesContext.getCurrentInstance() from a servlet" Watch "How to get FacesContext.getCurrentInstance() from a servlet" New topic
Author

How to get FacesContext.getCurrentInstance() from a servlet

xavi sala
Greenhorn

Joined: Mar 25, 2013
Posts: 1
HI,

I have a jsf form which submits payment details to a third party url which it returns the succes / error of the payment to my own servlet.

THe question is, how can I get my FacesContext from the servlet in order to add any error messages?

Regards,
Xavi
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15624
    
  15

Welcome to the JavaRanch, Xavi!

The FacesContext is not a durable data structure. It is created by the FacesServlet when a JSF URL request is received by the server and used to guide the lifecycle processing of that request. Once the request has been processed and the response has been sent back, it is destroyed. Therefore, the only servlet that can access the FacesContext is the FacesServlet itself. Likewise, since each request gets its own FacesContext, even code running under the FacesServlet cannot cache the FacesContext for later use. Once the current request is completed, the current FacesContext is useless.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to get FacesContext.getCurrentInstance() from a servlet
 
Similar Threads
Bean initiating a JSP/Servlet?
Maintaining transactions in a jsp application
sending https post request from servlet to another server
payment gateway integration: how to check payment status of particular order id
POST request via RestTemplate in JSON