i am learning struts2 from the book struts-2 in action. they say that for transferring data onto objects model-driven actions is preferred over object-backed beans properties.
can some1 explain me why they say so?
does the reason have something to do with the need to mention reference name in the view layer
In cases where you are dealing with several properties, the book advocates using an object to hold those properties, rather than having them directly on the action to make things easier for you. Consider the following examples:
In the second example, we set the properties directly on Widget (assuming that widget has a property1, property2, and property3).
Hopefully you can see how this would simplify your code in examples where you are dealing with a lot of properties.
Updated:
If you choose to implement
ModelDriven, then you would reference the properties above in your form asproperty1,property2,property3, etc. Additionally, since your action is driven by a single model, all form parameters are considered to be children of the model.If you choose not to implement
ModelDriventhen you would reference the properties above in your form aswidget.property1,widget.property2,widget.property3, etc. The upside to this approach is that you can have other properties on the action which don’t correspond to properties on widget.Aside from that, there is no difference. In fact, the book even says as much: