If a HTML form contains multiple input fields:
<form>
<input id="in1" type="text" value="one">
<input id="in2" type="text" value="two">
<input id="in3" type="text" value="three">
</form>
and is passed to a Spring controller as a serialized form like this:
new Ajax.Request('/doajax',
{asynchronous:true, evalScripts:true,
parameters: $('ajax_form').serialize(true)});
what Java type would be needed to read the serialized ajax_form in a Spring 3 controller?
@RequestMapping("/doajax")
@ResponseBody
public String doAjax(@RequestParam <?Type> ajaxForm
{
// do something
}
First of all, you use form fields without
names, soserialize()actually produces an empty result. Add names:I guess you use Prototype, so
parameters: $('ajax_form').serialize(true)produces a URL-encoded representation of the form (and also you don’t needtruehere, it adds unnecessary conversion). Since@RequestParamcan’t bind complex types, you can bind fields as separate parameters:Also you can create a class to hold form data and pass it as a model attribute:
–