Results 1 to 7 of 7

Thread: requireSession on SimpleFormController - "none was foun

  1. #1
    Join Date
    Aug 2004
    Posts
    17

    Default 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. #2

    Default

    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");
    }

  3. #3
    Join Date
    Aug 2004
    Posts
    17

    Default

    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

  4. #4

    Default

    Yes, that should do the same thing.

  5. #5
    Join Date
    Aug 2004
    Posts
    7

    Default

    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);
    ...
    }

  6. #6
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    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.
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  7. #7
    Join Date
    Aug 2004
    Posts
    17

    Default

    Quote 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

Similar Threads

  1. SimpleFormController not do onSubmit
    By heleno_alves in forum Web
    Replies: 2
    Last Post: Oct 18th, 2005, 07:22 AM
  2. Replies: 2
    Last Post: Jul 31st, 2005, 08:50 PM
  3. SimpleFormController Issue
    By zrawley in forum Web
    Replies: 14
    Last Post: Jul 31st, 2005, 07:27 AM
  4. Replies: 5
    Last Post: Jul 21st, 2005, 12:32 PM
  5. Servlet & portlet packages (SimpleFormController)
    By mpetrashev in forum Architecture
    Replies: 0
    Last Post: Dec 2nd, 2004, 10:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •