Spring 3 MVC: how to create the form-backing object at form submission?

8.5k Views Asked by At

I read a few tutorials about forms and submission in Spring 3 MVC. All these examples store the form backing object in the session the following way:

@SessionAttributes({"command"})

What I would like to do is to create the form object (for example: load it from the database) at the moment of form submission, not storing it in the session to be used at the moment of form submission.

How can I do this?

1

There are 1 best solutions below

0
On

Normally in Spring 3 you have only this line for form binding:

@RequestMapping(value = "/addContact", method = RequestMethod.POST)
public String addContact(@ModelAttribute("contact")
                        Contact contact, BindingResult result) {

(you can even skip the @ModelAttribute("contact") annotation)

There is no session.

May have a look at this tutorial: Spring 3 MVC: Handling Forms in Spring 3.0 MVC

But I already have requested you to post a link to the tutorial you used. -- Maybe we are talking about different things.