• 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
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

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

 
Ranch Hand
Posts: 176
  • 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: 9412
181
  • 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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!