• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

MVC Model 2 vs Spring SimpleFormController (Why formBackingObject() gets called twice?)

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In traditional MVC Model 2 applications after the user submits the form we build the model object and populate bind the form values into the bean using a controller manually.

Whereas in Spring why do we build the model object when the user is shown the form and again while we submit the form. I put in a couple of System.outs in my spring controller and I could see the formBackingObject() getting called both the times. Does that mean that two model objects are created? One when the user is presented the form and one while the form is submitted?

Is the object passed to onSubmit() is the same instance as the one created by formBackingObject()?

Please guide.

 
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think in your xxx-servlet.xml configuration on the controller you redirect it to the same page where the form original submitted.

For example,

To solve the problem you need to redirect it to the page you want (i.e success.htm etc)

You know that "formBackingObject()" is called first when the page is loaded and "ModelAndView onSubmit()" is called next when you submit the form.

Post your codes might be help for trouble shooting if you still have not solve the problem...
reply
    Bookmark Topic Watch Topic
  • New Topic