Session Scoped String Bean for Injection
I'm building an application in which I'd like to declare string beans, and scope them to session. This way, I can have a single string object I pass to all the controllers for each session. I want to do this for shared pieces such as a componentID. Each page needs the component ID, and I cannot pass the attribute in a get method. (The data cannot be displayed in the url bar.) I have some pages that are views, and others that are forms, so using post everywhere simply will not work.
Here is the relevant code:
Bean Def XML Note: actual class names changed to protect the strange and bewildered
Code:
<!-- Dependencies to inject into Controllers -->
<bean name="componentId" class="java.lang.String" scope="session">
<aop:scoped-proxy/>
</bean>
<bean name="sillyObjectId" class="java.lang.String" scope="session">
<aop:scoped-proxy/>
</bean>
<bean name="sillyObject" scope="session"
class="com.company.SillyObject">
<aop:scoped-proxy/>
</bean>
<!-- Controller Beans -->
<bean name="abstractSillyObjectPageController" abstract="true"
p:lkTimeZones-ref="lkTimeZones" <!-- defined in another bean file -->
p:sillyObjects-ref="SillyObjectCollection" <!-- defined in another bean file-->
p:sillyObjectId-ref="sillyObjectId"
p:componentId-ref="componentId"
p:selectedSillyObject-ref="SillyObject" />
<bean name="sillyObjectFormController" parent="abstractSillyObjectPageController"
class="com.company.controller.SillyObjectPageFormControllerImpl"
p:formView="sillyObjectPage"
p:successView="sillyObjectPage"
p:commandClass="com.company.SillyObject"
p:commandName="selectedSillyObject"
p:validator-ref="sillyObjectValidator" />
<bean name="relatedSillyObjectViewController" parent="abstractSillyObjectPageController"
class="com.company.controller.RelatedSillyObjectViewController"
p:appSchedules-ref="relatedSillyObjectCollection" <!--defined in another file -->
p:viewName="relatedSillyObjectPage"/>
So, as you can see, the intent is for all the controllers to share the data. When the app hits the entry page, they are set, and then we don't have to worry about it.
The problem is, when I configured (and finally got working thanks to the forums) the aop:scoped-proxy on the string declarations, I recieved the following error:
nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class java.lang.String
I realize that I can create container classes for the strings, (SillyObject has the attribute of sillyObjectId) but I'd really rather not do that. (There are more of these than what I have shown here.)
Any thoughts?