views:

21

answers:

1

Let's say you have a HTML form:

<form> 
 <input name = "in1" id="in1" type="text" value="one"> 
 <input name = "in2" id="in2" type="text" value="two"> 
 <input name = "in3" id="in3" type="text" value="three"> 
</form>

With @RequestParam you can bind fields as separate parameters:

public String doAjax(@RequestParam("in1") String in1, 
    @RequestParam("in2") String in2, @RequestParam("in2") String in2)

But you can also (supposedly) create a class to hold form data and pass it as a model attribute:

public class AjaxForm {
    private String in1;
    private String in2;
    private String in3;

    ... getters, setters ...
}

-

public String doAjax(AjaxForm form)

But what if some of the form fields have underscores?

Let's say the HTML form field is called "order_id" but the class field is called "orderId".

Is there any way to associate these without renaming the HTML?

With the @RequestParam annotation, you can do this by saying:

@RequestParam(value="order_id") String orderId

Is there a way to do something similar with the AjaxForm class above?

+2  A: 

All you need to do is name the property "order_id" in your form backing class:

public class AjaxForm {
    private String in1;
    private String in2;
    private String in3;
    private String order_id;

    ... getters, setters ...
}
James Earl Douglas