This is a migrated thread and some comments may be shown as answers.

Spring-Boot Kendo Grid Edit REST Call

1 Answer 1372 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 12 Mar 2015, 02:22 AM
Hello,

I am trying to get Kendo Grid to make a RESTful call after performing an in-line row edit. The call happens but it doesn't successfully make it's way to my spring-boot end-point, I keep getting a 400 Bad Request.

[KENDO CODE]
                    var dataSource = new kendo.data.DataSource({
                        transport: {
                            read:  {
                                url: "/customers",
                                type: 'GET',
                                dataType: "json"
                            },
                            update: {
                                url: "/customers/update",
                                type: 'PUT',
                                contentType: "application/json",
                                dataType: "json"
                            },
                            destroy: {
                                url: "/customers/destroy",
                                dataType: "json"
                            },
                            create: {
                                url: "/customers/create",
                                dataType: "json"
                            },
                            parameterMap: function(options, operation) {
                                if (operation !== "read" && options.models) {
                                    return {models : kendo.stringify(options.models)};
                                }
                            }
                        },
                        batch: true,
                        pageSize: 20,
                        schema: {
                            model: {
                                id: "id",
                                fields: myFields
                            }
                        }
                    });                
               
                    $("#grid").kendoGrid({
                        dataSource: dataSource,
                        height: 550,
                        groupable: true,
                        sortable: true,
                        editable: true,
                        filterable: {
                            extra: false,
                            operators: {
                                string: {
                                    startswith: "Starts with",
                                    eq: "Is equal to",
                                    neq: "Is not equal to"
                                }
                            }
                        },                        
                        pageable: {
                            refresh: true,
                            pageSizes: true,
                            buttonCount: 5
                        },
                        toolbar: ["create", "save", "cancel"],
                        columns: myColumns
                    });

[SPRING-BOOT CODE]
@RestController
@RequestMapping(value="/customers")
  public class CustomerRestController {
  @RequestMapping(value="/update", method = RequestMethod.PUT)
    public @ResponseBody List<Customer> update(@RequestBody List<Customer> cust) {
    ...
  }
}

[THE ERROR]
251{"timestamp":1426123694014,"status":400,"error":"Bad Request","exception":"org.springframework.http.converter.HttpMessageNotReadableException","message":"Could not read JSON: Unrecognized token 'models': was expecting ('true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@735e34; line: 1, column: 8]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'models': was expecting ('true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@735e34; line: 1, column: 8]","path":"/customers/update"}0

1 Answer, 1 is accepted

Sort by
-1
Atanas Korchev
Telerik team
answered on 16 Mar 2015, 07:33 AM
Hi Steven,

You can check the inline editing JSP demo which uses similar configuration. The difference is in the parameterMap:

function parameterMap(options,type) { 
   return JSON.stringify(options); 
}

Also here is how the controller looks like:

@RequestMapping(value = "/editing-inline/update", method = RequestMethod.POST)
    public @ResponseBody Product update(@RequestBody Map<String, Object> model) {
        Product target = new Product();
        
        target.setProductId((int)model.get("productId"));
        target.setProductName((String)model.get("productName"));
        target.setUnitPrice(Double.parseDouble(model.get("unitPrice").toString()));
        target.setUnitsInStock((int)model.get("unitsInStock"));
        target.setDiscontinued((boolean)model.get("discontinued"));
        target.setCategoryId((int)model.get("categoryId"));
        
        product.saveOrUpdate(target);
        
        return target;
    }

Regards,
Atanas Korchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Steven
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or