• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Ranch Hand
Posts: 111
1
  • 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: 60
1
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: 8870
166
  • 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?
 
What a stench! Central nervous system shutting down. Save yourself tiny ad!
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!