Announcement Announcement Module
Collapse
No announcement yet.
Session Persistence Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Session Persistence

    Hey everyone! How do you create a session and include user input? I want to persist a user's zipcode or city and state. I also want to update this session value if they update it through a form.

    I basically have a concert event viewer based by city and want the user to be able to look at venues around other cities, but ensure that the city he input persists as he navigates around the site.

    Any ideas?

  • #2
    I think you are better of using a framework to handle this for you. Since this is a spring forum i am going to suggest either Spring MVC or Spring Web Flow http://forum.springsource.org/showthread.php?t=89478

    Comment


    • #3
      i appreciate your response mahesh. i am currently using spring framework 3.0. should i post this within the 'Web' forum? thanks!

      Comment


      • #4
        Depends..can you tell me a little bit more about how your current architecture is laid out..what are you using as a framework for defining your user flows, navigation, error handling etc?

        Comment


        • #5
          i am using spring's web MVC framework using DispatcherServlet that dispatches requests to various controllers. hope this answers a few questions.

          Comment


          • #6
            I think what you are looking for is a session scoped bean..take a look at

            http://static.springsource.org/sprin...ther-injection

            Comment


            • #7
              yes! that is on the right path of what i am looking for. would you happen to have a link to an example of how to implement this? thanks

              Comment


              • #8
                There is an example in the link i posted earlier..section 3.4.4.5. Scoped beans as dependencies

                Comment


                • #9
                  the Client model that contains information such as their IP address, city, state, etc., i have attempted (based off this link's example) to inject the Client bean into my EventManagerImpl, but received this error:

                  Code:
                  org.springframework.beans.factory.BeanCreationException: 
                  Error creating bean with name 'eventManager' defined in ServletContext resource [/WEB-INF/myspring-servlet.xml]: 
                  Cannot resolve reference to bean 'client' while setting bean property 'client'; nested exception is org.springframework.beans.factory.BeanCreationException: 
                  Error creating bean with name 'client': 
                  Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: 
                  No thread-bound request found: 
                  Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? 
                  If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: 
                  In this case, use RequestContextListener or RequestContextFilter to expose the current request.
                  Here's my myspring-servlet.xml:

                  Code:
                  <bean id="client" class="myspring.model.Client" scope="session" />
                  	
                  <bean id="eventManager" class="myspring.service.EventManagerImpl">
                  	<property name="client" ref="client" />
                  </bean>

                  Comment


                  • #10
                    Try defining your bean like this

                    Code:
                    <bean id="client" class="myspring.model.Client" scope="session">
                     <aop:scoped-proxy/>
                    </bean>

                    Comment


                    • #11
                      Here's the latest error:

                      Code:
                      org.springframework.beans.factory.BeanCreationException: 
                      Error creating bean with name 'client' defined in BeanDefinition defined in ServletContext resource [/WEB-INF/myspring-servlet.xml]: 
                      Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice
                      And here is my myspring-servlet.xml file:

                      Code:
                      <?xml version="1.0" encoding="UTF-8"?>
                      
                      <beans xmlns="http://www.springframework.org/schema/beans"
                             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                             xmlns:aop="http://www.springframework.org/schema/aop"
                             xsi:schemaLocation="
                             http://www.springframework.org/schema/beans
                             http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                             http://www.springframework.org/schema/beans
                             http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                             http://www.springframework.org/schema/aop
                             http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
                      
                          <!-- the application context definition for the myspring DispatcherServlet -->
                      
                      	<bean name="/events.htm"    class="myspring.web.EventController"/>
                      	
                      	<bean id="client" class="myspring.model.Client" scope="session" >
                      		<aop:scoped-proxy />
                      	</bean>
                      	
                      	<bean id="eventManager" class="myspring.service.EventManagerImpl">
                      		<property name="client" ref="client" />
                      	</bean>
                      
                      </beans>

                      Comment


                      • #12
                        I did find some additional information on this topic. A session scopes a single bean definition to the lifecycle of a HTTP Session. Only valid in the context of a web-aware Spring ApplicationContext like XmlWebApplicationContext. If you try using these next scopes with regular Spring IoC containers such as the XmlBeanFactory or ClassPathXmlApplicationContext, you will get an IllegalStateException complaining about an unknown bean scope.

                        Comment


                        • #13
                          You are missing the aopalliance.jar from you application depedency. You can get it from http://aopalliance.sourceforge.net/

                          Comment

                          Working...
                          X