I am using primefaces 3.2, i have a problem while using a thread in JSF. I couldn’t get a reference to the current FacesContext from that thread.
How to get a reference to that context inside that thread.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The current
FacesContextis stored in a static thread-local variable. Servlet containers use a specific thread to process each request/response that arrives to the container so, storing theFacesContextin a thread-local variable ensures that there is just one instance per request processing lifecycle, which is how it should be.When you try to obtain a reference to a
FacesContextfrom another thread what happens is, since the it’s stored as a thread-local variable and since your new thread didn’t initialized it yet: you obtain anullreference.If you want/need a faces context in another new thread the only possible way is to create a new context instance by means of the
FacesContextFactory. However you will need a reference to aHttpServletRequest, aHttpServletResponseand aServletContextto instantiate it (and I guess you won’t be able to get valid references to those objects from a separate thread).