views:

766

answers:

1

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)

Manger 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?

+1  A: 

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);
Manolo Santos
How do I get access to the bean in the controller?
Craig Angus
You have to inject it. Or get it through your sessionBeanManager already injected.
Manolo Santos