The right way is something like we did in the webservice.rest module

> @RequestMapping(method = RequestMethod.POST)
> @ResponseBody
> public Object create(@RequestBody SimpleObject post, ...


(SimpleObject just extends LinkedHashMap<String, Object> or something)

This may require Spring 3, which we didn't switch to until OpenMRS 1.7. You
need to support 1.6 for HTML Form Entry, so I'd test this against 1.6 before
going with it.

Alternately you can can manually iterate through all attributes in the
request, as we discussed on irc.

-Darius

On Thu, Aug 4, 2011 at 10:19 AM, João Portela <[email protected]>wrote:

> 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
> ------------------------------
> Click here to 
> unsubscribe<[email protected]?body=SIGNOFF%20openmrs-devel-l>from 
> OpenMRS Developers' mailing list

_________________________________________

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