File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes @ModelAttribute behavior Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "@ModelAttribute behavior" Watch "@ModelAttribute behavior" New topic
Author

@ModelAttribute behavior

Reddy Prashanth
Ranch Hand

Joined: Aug 09, 2005
Posts: 61
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 :
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Reddy Prashanth
Ranch Hand

Joined: Aug 09, 2005
Posts: 61
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

Joined: Aug 09, 2005
Posts: 61
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
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: @ModelAttribute behavior