What is the difference between using commandName and modelAttribute when sending form data?
<form:form method="post" modelAttribute="csvFileUploadVO">
and
<form:form method="post" commandName="csvFileUploadVO">
At which point of time should I use either of them?
As Model needs a pair of name and value to populate, @ModelAttribute element 'value' is used as attribute name and the method returned object is used as value. If no 'value' is specified in @ModelAttribute then the returned type is used as the attribute name.
The commandName attribute is the most important attribute in the form tag, which specifies the model attribute name that contains a backing object and the properties of this object will be used to populate the generated form.
There is no difference, two different attributes exist for historical reasons.
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