• 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

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

 
Ranch Hand
Posts: 214
  • 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.
 
Master Rancher
Posts: 451
6
IntelliJ IDE Spring Fedora
  • 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: 10300
217
  • 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!