Spring's form tags: make sure you set the action
A colleague and I found a problem recently where if you specify a parameter on the URL which takes you to a Spring-powered form, and then submit that form you end up with multiple values for the same field item in the controller.
Example
- http://localhost/productDetails?serialNumber=12345A
Loads the product details form with serial number 12345A and displays the product details - User enters a different serial number 98765Z in the serialNumber input box and clicks "Get product details"
- Application received a serialNumber parameter contain an array of Strings: \["12345A", "98765Z"\]
If you use Spring's "
Solution
Another colleague (Richard) cleverly suggested that it could be to do with the form's action attribute and he was correct: to stop this behaviour you have to specify an action. You should be able to just use the mapping URL that you have bound into the controller (without the slash), so in my case my Controller looks like:
@ControllerAnd so my form tag looks like:
@RequestMapping("/productDetails")
public class ProductDetailsFormController {
...
}
<form:form modelAttribute="product" action="productDetails">This appears to work correctly for me, please let me know if you have any issues with this approach.
...
</form:form>
Technorati Tags: Spring, Form Tags, Andrew Beacock


Buy Stuff From Amazon 

1 Comments:
Thanks a lot.. .this solved my problem :)
Post a Comment