SparX
SparX

Reputation: 369

Backbone.js + Spring MVC. Save model

When I send a request from JSP FORM, the server side automatically parses data to my ModelObject. But when I send requests from Backbone save() my ModelObject is empty on Server Side. How can I do it like as JSP FORMs?

    @RequestMapping(value = "/member/ajax*", method = RequestMethod.POST)
    public void onSubmitAjax(Member member, HttpServletResponse response, HttpServletRequest request) throws Exception {
        //member is empty           
        memberManager.saveMember(member); 

    }

when I use GET it's working on Client Side:

@RequestMapping(value = "/member/ajax*", method = RequestMethod.GET)
    public
    @ResponseBody
    Member showForm(@RequestParam(required = false) Long id, HttpServletRequest request) throws Exception {
        Member member = memberManager.getMember(id);
        return member;
    }

Upvotes: 9

Views: 11815

Answers (2)

Sébastien Deleuze
Sébastien Deleuze

Reputation: 6219

I wrote a Spring MVC 3.1 backend for Backbone.JS Todo sample application. The code of the CRUD Controller may help you.

Based on your code sample, I think you should check that you have Jackson in your project dependencies, and use the following annotations for your onSubmitAjax method:

@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json") @ResponseStatus(HttpStatus.CREATED) @ResponseBody

You should also try RESThub, a nice Spring + Backbone.js stack provided with documentation, tutorial and code samples (Disclaimer: I am RESThub lead developer).

Upvotes: 18

rreyes1979
rreyes1979

Reputation: 1945

I am new too to Backbone.js, but give a look at http://documentcloud.github.com/backbone/#Sync-emulateJSON.

Upvotes: 1

Related Questions