I'm not sure if what I'm doing is wrong, or if I just missed an annotation or configuration item somewhere. Here's the situation:
I have a JSF application with a session-scoped bean named SessionData
. This bean has an application-scoped bean reference (of type ApplicationData
) injected into it at creation time. This works ok when the session is first created. The dependency injection is done with <managed-bean>
elements in the faces-config.xml
file as shown here:
<managed-bean>
<managed-bean-name>sessionData</managed-bean-name>
<managed-bean-class>my.package.SessionData</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>applicationData</property-name>
<property-class>my.package.ApplicationData</property-class>
<value>#{applicationData}</value>
</managed-property>
</managed-bean>
<managed-bean>
<managed-bean-name>applicationData</managed-bean-name>
<managed-bean-class>my.package.ApplicationData</managed-bean-class>
<managed-bean-scope>application</managed-bean-scope>
</managed-bean>
Because it doesn't make sense to have my SessionData
object include the ApplicationData
object when it is serialized, I have marked the ApplicationData
reference as transient in my SessionData
object:
transient private ApplicationData applicationData;
All is good until the web application is stopped (in my Tomcat 6.x container) and the sessions are serialized. When I restart the application and the sessions are deserialized, my reference to ApplicationData
is not re-injected by JSF. I know that deserialization is supposed to leave transient fields without a value. Is there a way to signal JSF that this session-scoped object requires its dependencies be set again after deserialization?
I am using MyFaces JSF 1.2 and Tomcat 6.0.26 as my web application container.