PDA

View Full Version : requireSession on SimpleFormController - "none was foun


fbos
08-18-2004, 05:41 PM
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:
javax.servlet.ServletException: This resource requires a pre-existing HttpSession: none was found
org.springframework.web.servlet.support.WebContent Generator.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

bobmanc
08-18-2004, 09:34 PM
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");
}

fbos
08-18-2004, 10:38 PM
But, isn't that the same thing as doing:
<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

bobmanc
08-19-2004, 07:55 AM
Yes, that should do the same thing.

bknights
08-19-2004, 03:13 PM
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);
...
}

irbouho
08-19-2004, 04:27 PM
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

/**
* <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.

fbos
08-22-2004, 09:56 PM
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