Reputation: 23198
In my application I need to gather information on one screen and then display it on the next.
I have selected to store this information in a bean with a scope set as session ( it will be used in several other screens after the initial data gathering screen)
The Manager is configured as follows:
<bean name="/springapp.htm" class="foo.bar.controller.springcontroller">
<property name="sessionBeanManager" ref="sessionBeanManager" />
</bean>
The bean is configured as follows :
<bean id="sessionBean" class="foo.bar.sessionBean" scope="session">
<aop:scoped-proxy/>
<property name="beanValue" value="defaultValue" />
</bean>
<bean id="sessionBeanManager" class="foo.bar.sessionBeanManagerImpl">
<property name="sessionBean" ref="sessionBean"/>
</bean>
And I am outputting on the jsp page with
<c:out value="${sessionBean.beanValue}"></c:out>
but whenever I load the page the value is empty?
It seems to me that the bean is loading OK but is not populated with the value, which leads me to think that either the session bean is not being populated or the bean is not being created as a session bean?
Upvotes: 3
Views: 10846
Reputation: 26584
You can reference spring session beans with the following syntax in your EL in the jsp.
${sessionScope['scopedTarget.messageUtil'].flashMessages}
That calls getFlashMessages() on this bean
<bean id="messageUtil" class="mypackage.MessageUtilImpl" scope="session">
<aop:scoped-proxy proxy-target-class="false"/>
<property name="messageSource" ref="messageSource" />
</bean>
Upvotes: 8
Reputation: 1913
Spring beans are not visible in the views (JSPs in your case) unless you add them first to the model.
You have to add your sessionBean to the model in the controller to make it available to the view.
model.addAttribute("sessionBean", sessionBean);
Upvotes: 2