JSF Session Failover Issue
I'm having some problems with a session-scoped pagecode object in a failover scenario and would appreciate any suggestions. Here's the situation:
I have a pagecode class that retrieves a user bean from the session in an action listener method. In a standalone server environment it works just fine,
and even in a clustered environment it works okay -- until the server on which the user is operating is taken down. The session data is successfully failed
over to the other server and the user's next request is routed to said server. However, if the aforementioned action listener method is then invoked, I now
get IllegalStateExceptions when trying to get the user bean out of the session. Here's the code:
publicclass MyPagecodeextends PageCodeBaseimplements Serializable{
publicvoid firePrepareForPreview(ActionEvent event){
UserBean user = UserBean.getFromSessionScope(this.getSessionScope());
//do something with the user bean
}
}
publicclass PageCodeBase{
public PageCodeBase(){
getSessionScope();
}
protectedtransient Map sessionScope =null;
public Map getSessionScope(){
if(sessionScope ==null){
sessionScope =
(Map)FacesContext.getCurrentInstance()
.getApplication()
.createValueBinding("#{sessionScope}")
.getValue(facesContext);//this line is reached either
//a) in a standalone server mode when the pagecode object is created (this works),
//b) via the action listener method above after the object is failed over, causing the sessionScope variable
//to be set to null (not serializable)
}
return sessionScope;
}
}
Stack Trace:
Caused by: javax.faces.el.EvaluationException: java.lang.IllegalStateException
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:131)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:73)
... 32 more
Caused by: java.lang.IllegalStateException
at com.sun.faces.context.FacesContextImpl.assertNotReleased(FacesContextImpl.java(Compiled Code))
at com.sun.faces.context.FacesContextImpl.getApplication(FacesContextImpl.java:122)
at pagecode.PageCodeBase.getSessionScope(PageCodeBase.java:254)
at pagecode.enews.admin.EditMessage.previewMessage(EditMessage.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java(Compiled Code))
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java(Compiled Code))
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:127)
... 33 more
It's apparent that calling createValueBinding is okay when the pagecode object is constructed by the faces runtime (happens when all servers are
go), but not from within my action listener method (happens when failover occurs). Perhaps I cannot call createValueBinding during this phase, but I've
tried calling getExternalContext() as well to no avail. I don't see how I"m supposed to get the userbean out of the session in this scenario.
If I shouldn't be accessing the session data from an actionlistener or an action, what is the correct way to do it? Any help you can offer would be appreciated. Thx

