Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • 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
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

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

 
Ranch Hand
Posts: 238
2
  • 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.
 
Rancher
Posts: 493
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: 10649
227
  • 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?
 
That is a really big piece of pie for such a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!