I'm trying to send a map of key-value pairs as an AJAX request (in
Javascript code) to a controller (annotated Spring MVC). For instance, I
want to send this Object:

var attributes = { 'attr1' : 'value', 'attr2' : 'value2' };

$j.ajax({
    type: "POST",
    url: ajaxUrl,
    data: {
        'id': 'test',
        'attributes': attributes
    }
});

Ideally I would want something like this:

@RequestMapping(value=ajaxUrl, method=RequestMethod.POST)
public void getPreviewHtml(@RequestParam("id") String id,
@RequestParam("attributes") Map<String,String> attributes,
HttpServletRequest request, HttpServletResponse response) throws Exception {
 //...
}

However the RequestParam doesn't work for the Map. The request above
produces the following Form Data:

id: test
attributes[attr1]: value
attributes[attr2]: value2

Do you know how can I get that Form Data into a Map? Or any other approach
for the same effect. Basically I can have a variable number of attributes
and I want a way to fetch all of them.

Thanks

_________________________________________

To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to 
[email protected] with "SIGNOFF openmrs-devel-l" in the  body (not 
the subject) of your e-mail.

[mailto:[email protected]?body=SIGNOFF%20openmrs-devel-l]

Reply via email to