This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques and have Mario Casciaro & Luciano Mammino on-line!
See this thread for details.
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

@ModelAttribute behavior

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
I am trying to learn spring annotation in MVC. I am using spring 3.4 version. I am not using any @ModelAttribute annotation for the method parameters in my controller processSubmit() method. But still , in the final result page (pizzaSuccess.jsp here), my command object is bound in the request scope with a name "pizza". Plese note that , i am not using the name "pizza" anywhere in my controller. My command object is of type "Pizza".

Does it mean, if we dont use any @ ModelAttribute annotation, by default will it use my command type as name ?? Can someone help me to understand this clearly.

Below is my controller code :
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand what exactly your question is about? What are you looking for exactly. I understand, sometimes english isn't someones native language, but I think the question is getting lost here. Can you try to re-phrase it?

Also "I am using spring 3.4 version."

The latest version of Spring is 3.1. So are you from the future? Can you tell us who wins all the sporting events from now to where you are so we can make lots of money??? Please?

Thanks

Mark
 
Reddy Prashanth
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sorry.. It was a typo. I am using spring 3.0.4 version.
My question is :

Does it mean, if we dont use any @ ModelAttribute annotation, by default will it use my command type as name ?? Can someone help me to understand this clearly.


In my code , for the processSubmit() method, I am not using any @ModelAttribute annotation (at parameter level or at the method level). Still my model is available in the pizzasuccess.jsp view page (under request scope with name "pizza"). I am not using this "pizza" name anywhere in my controller.

Can someone explain me how this happens ? If this is default behavior, when we need to use @ModelAttribute annotation.
Hope this time, my question is clear


 
Reddy Prashanth
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I found answer to my question. Though I read the documentation before, I somehow overlooked.

"Command/form objects to bind parameters to: as bean properties or fields, with customizable type conversion, depending on @InitBinder methods and/or the HandlerAdapter configuration - see the "webBindingInitializer" property on AnnotationMethodHandlerAdapter. Such command objects along with their validation results will be exposed as model attributes, by default using the non-qualified command class name in property notation (e.g. "orderAddress" for type "mypackage.OrderAddress"). Specify a parameter-level ModelAttribute annotation for declaring a specific model attribute name."

Thank you !!
 
Mark Spritzler
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cool.

So what you are saying is that the form has data from the first Pizza object created in the get, then when you submit the form the Pizza is put into the model under the class name "pizza" and therefore the Pizza object is automatically passed in as a correct parameter to the Pizza parameter in the submitProcess method?

Mark
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic