0 Replies Latest reply on Sep 14, 2012 10:46 AM by samwun9988

    session bean lost values.

    samwun9988

      Hi,

       

      I tried to use spring mvc 3.1 session scope to pass values from child page back to parent page (jsp), but the value is lost after refresh the parent page.

       

      Here is my TestController code:

       

       

      @Controller

      public class TestController {

       

       

          private static final Logger logger = Logger.getLogger(TestController.class);

         

          @Autowired

          private CategorySessionBean categorySessionBean;

         

         

          @RequestMapping(value = "/", method = RequestMethod.GET)

          public String home(Model model) {

              logger.debug(" =======HOME PAGE========");

              model.addAttribute("categorySessionBean", categorySessionBean);

              return "index";

          }

       

          @RequestMapping(value = "/popupPage", method = RequestMethod.GET)

          public String popupPage(Model model) {

              logger.debug(" =======POPUP PAGE========");

              logger.debug(" =======categorySessionBean: ========"+categorySessionBean.toString()); // all fields in this session bean thave lost when child javascript refresh parent page.

              model.addAttribute("categorySessionBean", categorySessionBean);

              return "popupPage";

          }

         

          @RequestMapping(method = RequestMethod.POST)

          public String processPopupPageSubmit(

              @ModelAttribute("categorySessionBean") CategorySessionBean categorySessionBean, BindingResult result, SessionStatus status) {

              logger.debug(" =======processSubmit========");

             logger.debug(" =======categorySessionBean: ========"+categorySessionBean.toString());  // after filled in the fields of this session bean in popupPage and click on submit, all values are store here.

              return "popupPage";

          }

      }

       

       

      parent jsp file (index.jsp):

       

       

      <%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>

      <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

      <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

      <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

      <%@taglib  uri="http://www.springframework.org/tags" prefix="spring" %>

      <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

       

       

      <%@page contentType="text/html" pageEncoding="UTF-8"%>

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

         "http://www.w3.org/TR/html4/loose.dtd">

       

       

      <html>

          <head>

              <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

              <title>JSP Page</title>

          </head>

          <body>

              <form:form id="form" name="add_category_form" modelAttribute="categorySessionBean" action="save" method="post" >

                          <form:errors path="*" class="error" element="div" />

                          <form:input type="text" path="name"></form:input><br>

                          <form:input type="text" path="description"></form:input><br>

                          <form:input type="text" path="id"></form:input><br>

                          <a href="#" onclick="openUploadImagePage()">click to popup</a> <br>

                          <input type=BUTTON value="Submit" name="mySubmit" onClick="submitform()">

              </form:form>

          </body>

      </html>

       

       

      <script type="text/javascript">

          function submitform() {

                  this.document.forms['add_category_form'].submit();

                }

               

          function openUploadImagePage() {

              window.open('popupPage','Popup Page','width=600,height=400');

          }

       

       

      </script>

       

       

      popup child jsp (popupPage.jsp) file:

       

      <html>

          <head>

              <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

              <script language="JavaScript">

                   function refreshParent() {

                       var URL = unescape(window.opener.location.pathname); 

                       var PARMS = unescape(window.opener.location.search);

       

       

                       var ms = new Date().getTime();

                       window.opener.location.href="/TestSession-1.0/popupPage"+PARMS;

                       window.close();

                   }

              

              </script>

              <title>JSP Page</title>

          </head>

          <body>

              <form:form id="form" name="add_category_form" modelAttribute="categorySessionBean" action="save" method="post" >

                          <form:errors path="*" class="error" element="div" />

                          <c:choose>

                              <c:when test='${not empty categorySessionBean.name}'>

                                  <script language="JavaScript">

                                      this.refreshParent();

                                  </script>

                              </c:when>

                             

                          </c:choose>

                          <form:input type="text" path="name"></form:input><br>

                          <form:input type="text" path="description"></form:input><br>

                          <form:input type="text" path="id"></form:input><br>

                          <a href="#" onclick="openUploadImagePage()">click to popup</a> <br>

                          <input type=BUTTON value="Submit" name="mySubmit" onClick="submitform()">

              </form:form>

          </body>

      </html>

       

      <script type="text/javascript">

          function submitform() {

                  this.document.forms['add_category_form'].submit();

                }

               

          function openUploadImagePage() {

              window.open('/popupPage','Popup Page','width=600,height=400');

          }

       

      </script>

       

       

      mvc-config.xml file:

       

       

      <mvc:annotation-driven/>

       

       

                <mvc:resources mapping="/resources/**" location="/, classpath:/META-INF/web-resources/" />

                <mvc:default-servlet-handler />

         

              <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

                  <property name="prefix" value="/WEB-INF/"/>

                  <property name="suffix" value=".jsp"/>

              </bean>

                <!-- Map paths directly to view names without controller processing. Use the view-name attribute if necessary: by convention the view name equals the path without the leading slash -->

       

              <mvc:view-controller path="/" view-name="index" />

             

              <!-- an HTTP Session-scoped bean exposed as a proxy -->

              <bean id="categorySessionBean" class="testsession.domain.bean.CategorySessionBean" scope="session">

                 <!-- this next element effects the proxying of the surrounding bean -->

                 <aop:scoped-proxy/>

              </bean>

       

       

      Any suggestion is very appreciated.

      Thanks

      Sam