Is there a way to keep track of FacesContext after restarting Tomcat? For example: I am logged in. Server is being updated and restarted. The UserSessionBean keeps the Login alive. But message properties from ResourceBundle need FacesContext.getCurr… to be able to show the right message. FacesContext is not serializable and i guess extending it, making the child class serializable is not a good idea (i do not want to change everything in the code, where facescontext is used, and i do not know what jsf does with FacesContext). So is there a way to somehow serialize the faces context?
As I explained in another current thread, the FacesContext is not a durable object. It is created to handle a single JSF HTTP request and destroyed as soon as that request has been processed. So even if you could serialize it, it would be not merely useless, but actually harmful to attempt to use it anywhere else - as people occasionally discover when they attempt to stuff it into session objects and the like.
Customer surveys are for companies who didn't pay proper attention to begin with.
Joined: Sep 11, 2012
Thank you for your reply. I guess I understand now. But is there a way to not have FacesContext.getCurrentInstance() beeing null after server restart? How does this work in other applications. I cannot be the only person that needs to use the resource bundle without having the user to log in again after server restart. Am i not getting this?
It doesn't matter whether you restart the server or not.
The FacesContext only exists while a JSF HTTPServletRequest is actually being processed, and every HTTPServletRequest has a unique FacesContext constructed for it.
Non-JSF HTTPSeervletRequests (meaning any request that doesn't go through the FacesServlet) will not have a FacesContext and attempting to obtain one will return NULL, since it is the FacesServlet that constructs and initializes the FacesContext.
On top of that, resource bundles are not controlled by logins. They're there whether you log in or you don't. But if you want access to them outside of the scope of a JSF process request, you have to get hold of them the hard way.
Joined: Sep 11, 2012
Thanks Tim, that you took the time, to make this clear to me again. But how would I get hold of resource bundles "the hard way"? Any java implementation i find uses the FacesContext.getCurrentInstance() method. Could you please point me in the right direction?