Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle unknown number of parameters with Spring MVC

I want to use JQuery's Sortable (http://jqueryui.com/sortable/#connect-lists), so my left list will end with something like this

<ul>
    <li>
        Some txt1 
        <input type="hidden" name="li1" value="1"/>
    </li>
    <li>
        Some txt2 
        <input type="hidden" name="li2" value="2"/>
    </li>
</ul>

The number of <li> will be different every time. My idea is to get all hidden inputs values and names put them in array and POST the array as JSON data, but how should my Controller look like? Is there a way to "wait" for list of something in the controller. For example:

@RequestMapping(value = "/listItems")
    public @ResponseBody GridModel getUsersForGrid(@RequestParam(value = "items") List<NameIdPair> items){...}
like image 651
Evgeni Dimitrov Avatar asked Nov 25 '12 12:11

Evgeni Dimitrov


1 Answers

you can inject a instance of Map holding all parameters.

@RequestMapping("/listItems")
public @ResponseBody GridModel getUsersForGrid(@RequestParam Map<String, String> params) {
    params.get("parametername");
    // ...
}
like image 171
Yevgeniy Avatar answered Oct 17 '22 06:10

Yevgeniy