• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Questions on code related to Spring MVC

 
Ranch Hand
Posts: 73
2
  • 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: 653
14
TypeScript 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: 2264
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic