Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

CanJS and Play! framework 1.2.x

$
0
0
Hi.

I'm trying to using CanJS with Play! Framework 1.2.x (http://www.playframework.com/) as backend. Models are defined at backend.

Consider the following code snippets.
Server-side, model Todo:
  1. public class Todo extends Model {
  2.     public String name;
  3. }
Client-side:
  1. <script>
  2.     var Todo = can.Model({
  3.         findAll: 'GET /todos',
  4.         findOne: 'GET /todos/{id}',
  5.         create: 'POST /todos',
  6.         update: 'PUT /todos/{id}',
  7.         destroy: 'DELETE /todos/{id}'
  8.     },{
  9.     });

  10.     var todo = new Todo({name: "pick up cherries and apples"});
  11.     todo.save( function(todo){
  12.         console.log( todo.id, todo.name );
  13.     });
  14. </script>
I can fetch models from backend using findAll() and findOne() methods successfully. But when I trying to create model I got a problem.

todo.save() sends parameter "name" with value "pick up cherries and apples" to server.
But Play! framework expects that parameter name should be "todo.name" to successfully bind sent data with Todo model.

I can change this behavior on the server-side by prepending parameter name "name" with "todo." but it looks a little messy.
So my question is - can I change this default behavior on the client-side?
--
Best regards,
Pavel Derendyaev


Viewing all articles
Browse latest Browse all 3491

Trending Articles