• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FacesContext serializable?

 
Simon Mary
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
Cheers!
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18281
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Simon!

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.
 
Simon Mary
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18281
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Simon Mary
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18281
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"The hard way" means the way you do it in any non-JSF servlet or JSP (but Bear will growl at you if you load up JSPs with scriptlets! ).

I forget the details - you'll have to check the JavaDocs, but it goes something like this:


Where "MyResources" is on the classpath of the application (typically in WEB-INF/classes).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic