2015-09-28 4 views
1

Я использую KendoUI, и у меня есть datagrid, в котором я пытаюсь обновить данные в строке inline. Когда я нажимаю кнопку редактирования, отображаются кнопки UPDATE и CANCEL. Когда я нажимаю кнопку UPDATE, ничего не происходит. Я отладил эту проблему с помощью инструментов разработчика Chrome, и я поставил точку останова, где, как я думал, появится ошибка (-ы). Тем не менее, нет ошибок, возникающих в связи с функциональностью UPDATE источника данных KendoUI Grid. Вот отрывок из моего кода:Kendo UI: Data Grid Update Rest Call Не работает

endorsementsTabGridDataSource = new kendo.data.DataSource({ 
    type: "json", 
    transport: { 
     read: { url:function (obj){ 
      return "/${applicationScope.contextName}/admin/endorsements/api?templateVersionSysId=" + 201442 + "&formCode=" + '7610810' + "&state=" + "FL" 
      // url: "/${applicationScope.contextName}/admin/endorsements/api?templateVersionSysId=" + $("#templateVersionSysId").val() + "&formCode=" + formCode + "&state=" + stateCode 
     } 
    }}, 

    update: { 
     url: function (obj) { 
      return "/${applicationScope.contextName}/admin/endorsements/api" 
     }, 
     type: "POST", 
     dataType: "json", 
     contentType: "application/json", 
     data: function(data){ 
      return kendo.stringify(data) 
     } 
    }, 

    parameterMap: function (options, operation) { 
     /* if ((operation === "create" || operation === "update") && options) { 
      options.state = states.value(); 
      options.templateVersionSysId = $("#templateVersionSysId").val(); 
      options.formCode = formCode; 
     } 

     if (operation !== "read" && options) { 
      return kendo.stringify(options); 
     }*/ 

     return JSON.stringify(options) 
    }, 

    batch: false, 
    error: function (xhr, status, error) { 
     notification.show('Error occured in Endorsements Tab: ' + xhr.responseText, "error"); 
    }, 
    schema: { 
     model: { 
      id: "customEndorSysId", 
      fields: { 
       fieldKey: {editable: false, nullable: false}, 
       name: { editable: true, nullable: false}, 
       description: {editable: true}, 
       state: {editable: false, nullable: true}, 
       templateFldSysId: {editable: false, nullable: false} 
      } 
     } 
    } 

}); 

В дополнение к упомянутой выше JQuery вызов остальное делает вызов на MVC контроллер Spring. Класс контроллера предшествует

@RequestMapping("/admin/endorsements") 

метод, который вызывается является следующим кодом Java:

@ResponseBody 
@RequestMapping(value = {"/api"}, method = {RequestMethod.PUT, RequestMethod.POST}, produces = {"application/xml", "application/json"}, headers = {"application/json"}) 
public ResponseEntity updateEndorsement(@RequestBody String customEndorsementDescription) { 

    try { 
     // hibernateDao.initAuditFields(customEndorsementDescription, principal); 
     // hibernateDao.saveOrUpdate(customEndorsementDescription); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } finally { 

    } 
    return new ResponseEntity(customEndorsementDescription, HttpStatus.OK); 
} 

ответ

0

Я понял, что моя проблема была. Проблема возникает из-за плохого структурирования спокойного вызова на стороне клиента. Вызов обновления был за пределами объекта транспорта. См исправленный код ниже:

endorsementsTabGridDataSource = new kendo.data.DataSource({ 
    transport: { 
     read: { url: "/${applicationScope.contextName}/admin/endorsements/api?templateVersionSysId=" + 201442 + "&formCode=" + '7610810' + "&state=" + "FL" 
      // url: "/${applicationScope.contextName}/admin/endorsements/api?templateVersionSysId=" + $("#templateVersionSysId").val() + "&formCode=" + formCode + "&state=" + stateCode 
     }, 
     update: { 
      url: "/${applicationScope.contextName}/admin/endorsements/api/test", 
      type: "POST", 
      dataType: "json", 
      contentType: "application/json" 
     }, 
     parameterMap: function (options, operation) { 
      if (operation !== "read") { 
       //console.log("Models: ", options.models); 
       options.key = options.fieldKey; 
       options.stateText = stateCode; 
       return JSON.stringify(options); 
      } 
      return options; 
     }}, 
    batch: false, 
    schema: { 
     model: { 
      id: "customEndorSysId", 
      fields: { 
       fieldKey: {editable: false, nullable: false}, 
       name: { editable: true, nullable: false}, 
       description: {editable: true} 
      } 
     } 
    } 

}); 

На стороне контроллера бэкенд, я должен был сделать следующие изменения:

@ResponseBody 
@RequestMapping(value = {"/api/test"}, method = {RequestMethod.POST}, consumes = {MediaType.APPLICATION_JSON_VALUE}, produces = {MediaType.APPLICATION_JSON_VALUE}) 
public ResponseEntity updateEndorsement(@RequestBody EndorsementDescription customEndorsementDescription, Principal principal) { 

    TrTemplateEndorDesc trTemplateEndorDesc = new TrTemplateEndorDesc(); 
    try { 

     hibernateDao.initAuditFields(customEndorsementDescription, principal); 
     trTemplateEndorDesc.setAuditRecCreateApplId(customEndorsementDescription.getAuditRecCreateApplId()); 
     trTemplateEndorDesc.setAuditRecCreateApplUserId(customEndorsementDescription.getAuditRecCreateApplUserId()); 
     trTemplateEndorDesc.setAuditRecCreateDbUserId(customEndorsementDescription.getAuditRecUpdtDbUserId()); 
     //trTemplateEndorDesc.setAuditRecCreateDts(customEndorsementDescription.getAuditRecCreateDts()); 
     hibernateDao.saveOrUpdate(trTemplateEndorDesc); 

    } catch (Exception e) { 
     //e.printStackTrace(e.printStackTrace() + e.getCause()); 
     throw new RuntimeException("Unknown Exception", e.getCause()); 
    } finally { 

    } 
    return new ResponseEntity(customEndorsementDescription, HttpStatus.OK); 
} 
Смежные вопросы