Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Why do we have to send an empty model object to View in Spring?  RSS feed

 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, this question is from Form Validations in Spring.

Here's the method in Controller class:


May I know why do we have to send an empty Customer instance to the JSP before the form passes the field parameters to the Controller?

How does modelAttribute=customer work in HTML form? Does JSP page binds the form parameters to the Customer object right there in JSP page or they are bound once the parameters are passed to the Controller?


Thanks.
 
Ranch Hand
Posts: 207
2
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't have to use the model attribute as far as I know.  Just have the name=""  in the html match the property of the object and spring will automatically fill it in.  

For your question, I'm pretty sure it is bound right there in the page, then the object is sent. 
 
Saloon Keeper
Posts: 9134
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You asked the exact same question here: https://coderanch.com/t/695520/frameworks/Model-parameter-Controller-method#3265392

Was the answer not satisfactory?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!