I guess I don't understand the difference between a "FormBackingObject" and a "ModelAttribute" in spring MVC.
Seems like both gets initiated and populated by Spring with an incoming request.
@ModelAttribute is an annotation that binds a method parameter or method return value to a named model attribute, and then exposes it to a web view. In this tutorial, we'll demonstrate the usability and functionality of this annotation through a common concept, a form submitted from a company's employee.
@ModelAttribute is used for binding data from request param (in key value pairs), but @RequestBody is used for binding data from whole body of the request like POST,PUT.. request types which contains other format like json, xml.
formBackingObject. protected Object formBackingObject(HttpServletRequest request) throws Exception. Retrieve a backing object for the current form from the given request. The properties of the form object will correspond to the form field values in your form view.
@ModelAttribute can be used to expose command objects to a web view, using specific attribute names, by annotating corresponding parameters of an @RequestMapping method.
Good question. This comes down to a difference in terminology between Spring 2.0 MVC, which used a controller class hierarchy, and Spring 2.5 MVC, which uses annotations.
The "form backing object" is the object which the Spring 2.0-style AbstractFormController
(and subclasses like SimpleFormController
) would use to bind the form data on to.
@ModelAttribute
does much the same thing for Spring 2.5-style annotated controllers, but in a less rigid way.
So you're right in that the two do pretty much the same thing, but the style is really quite different. Both are valid approaches, and both are supported in Spring 2.5 (and 3.0).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With