Announcement Announcement Module
Collapse
No announcement yet.
requireSession on SimpleFormController - "none was foun Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • requireSession on SimpleFormController - "none was foun

    Hi !

    In one of my SimpleFormController subclasses, I enabled session support, by setting "requireSession" to true.

    When I browse the page in question, I get the following exception:
    Code:
    javax.servlet.ServletException: This resource requires a pre-existing HttpSession: none was found
        org.springframework.web.servlet.support.WebContentGenerator.checkAndPrepare(WebContentGenerator.java:171)
    ...
    Obviously, I need to execute request.getSession(true) somewhere, but I can't find how to do it.

    None of the Spring examples use Session forms, so I don't have anything to base myself on.

    Can anyone give me a hand ?

    Thanks !
    François

  • #2
    You can create a constructor for your controller and call setSessionForm from there like this...
    public MyFormController()
    {
    setSessionForm(true);
    setValidateOnBinding(false);
    setCommandName("MyForm");
    setFormView("MyForm");
    }

    Comment


    • #3
      But, isn't that the same thing as doing:
      Code:
      <bean class="...Controller">
      <property name="sessionForm"><value>true</value></property>
      </bean>
      That's what I'm doing in my *-servlet.xml, and I get an exception when the controller is called to initially render the form.

      Thanks,
      François

      Comment


      • #4
        Yes, that should do the same thing.

        Comment


        • #5
          I believe setSessionForm only lets the form know to be session aware (though it doesn't seem to work as I expect with regards to caching a command object).

          You need to create the session in either your code or via a jsp page directive:

          <jsp:directive.page session="true"/>
          or
          <%@ page session=”true” %>


          I don't know what declarative methods there are to create a session if you aren't using jsp. Any of the methods that accept a request could be used to request.getSession(true);
          e.g.
          protected Object formBackingObject(HttpServletRequest request) throws ServletException {
          request.getSession(true);
          ...
          }

          Comment


          • #6
            I believe setSessionForm only lets the form know to be session aware (though it doesn't seem to work as I expect with regards to caching a command object).
            that's true. following is an excerpt from Spring source
            Code:
            /**
             * <p>Form controller that autopopulates a form bean from the request.
             * This, either using a new bean instance per request, or using the same bean
             * when the <code>sessionForm</code> property has been set to <code>true</code>.
             *...
             */
            SimpleFormController will use your bean only if it is already instanciated and stored in the HttpSession.

            Comment


            • #7
              Originally posted by bknights
              I don't know what declarative methods there are to create a session if you aren't using jsp. Any of the methods that accept a request could be used to request.getSession(true);
              e.g.
              protected Object formBackingObject(HttpServletRequest request) throws ServletException {
              request.getSession(true);
              ...
              }
              In the end, that's what I did. Works fine, now.

              Thanks everyone for the help.

              Bye !
              François

              Comment

              Working...
              X