wood burning stoves 2.0*
The moose likes JSF and the fly likes FacesContext serializable? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "FacesContext serializable?" Watch "FacesContext serializable?" New topic
Author

FacesContext serializable?

Simon Mary
Greenhorn

Joined: Sep 11, 2012
Posts: 3
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

Joined: Jun 25, 2001
Posts: 16061
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Simon Mary
Greenhorn

Joined: Sep 11, 2012
Posts: 3
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

Joined: Jun 25, 2001
Posts: 16061
    
  21

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

Joined: Sep 11, 2012
Posts: 3
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

Joined: Jun 25, 2001
Posts: 16061
    
  21

"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).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FacesContext serializable?