Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Questions on code related to Spring MVC

 
Ranch Hand
Posts: 61
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Friends,

I am learning Spring MVC and I am unable to understand the difference between two examples.

1st example uses html form(helloWorld-form.jsp, helloWorld.jsp) while the 2nd example uses spring form(student-form.jsp, student-confirmation.jsp).

The corresponding HelloWorldController has  two methods namely showForm and processFormVersion3 while the StudentController has methods  showForm and processForm.

My questions are:

1. What is the advantage of using spring form over html form?
2. Why in the HelloWorldController the model's setAttribute is called in the  processFormVersion3 method while in the StudentController it is called in the showForm method? When exactly should the model's setAttribute method be called?
3. In the StudentController' showForm method,  what is the point of adding an empty Student object in the model?

1. helloWorld-form.jsp



2. student-form.jsp



3. helloWorld.jsp



4. student-confirmation.jsp



5. HelloWorldController




6. StudentController

 
Bartender
Posts: 558
10
IntelliJ IDE Spring Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to add an empty object because otherwise it will be null i think.  You can try it without adding the object and see what happens
 
Bartender
Posts: 2119
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no definite answer why the setAttribute is used in one method , but not another.
As long as the methods needs to set the attribute and pass it along to the form , then the setAttributed method is used.

Also, Spring form provides some more library tags than html tags. When those library tags are needed to build the front end page, then use it.
Thymeleaf is very popular for building front end for Spring application now.
 
reply
    Bookmark Topic Watch Topic
  • New Topic