ParamQuery grid support forum
General Category => Help for ParamQuery Grid (free version) => Topic started by: Chaitanya21 on February 23, 2017, 12:01:28 pm
-
My child grid data model is like:
var gridDetailModel = function( $gridMain, rowData ){
return {
height: 130,
//pageModel: { type: "local", rPP: 5, strRpp: "" },
dataModel: {
url: "/ExpenseManagement/departmentHead",
location: 'remote',
//sorting: 'local',
dataType: 'JSON',
data: JSON.stringify(jsonToBeSend),
async: true,
beforeSend: function(xhr,setting) {
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
},
method: "POST",
//contentType:'application/json; charset=UTF-8',
error: function () {
//$gridMain.pqGrid( 'rowInvalidate', { rowData: rowData });
}
//url = "/pro/orderdetails.php?orderId=" + orderID //for PHP
},
colModel: [
{ title: "BranchName", width: 80, dataIndx: "branchId" }
],
editable: false,/*
groupModel: {
dataIndx: ["branchId"],
dir: ["up"],
title: ["{0} - {1} product(s)"],
icon: [["ui-icon-triangle-1-se", "ui-icon-triangle-1-e"]]
}, */
flexHeight: true,
flexWidth: true,
numberCell: { show: false },
title: "Order Details",
showTop: false,
showBottom: false
};
JSON data:
/* var jsonToBeSend=new Object();
jsonToBeSend["id"] = 1;
jsonToBeSend["success"] = true;
jsonToBeSend["message"] = "ghgj"; */
/* var jsonToBeSend="{\"data\":{\"id\":1}}"; */
var jsonToBeSend={"id":1};
I tried all the combination of JSON.
I getting below error:
11:38:46.051 DEBUG o.s.w.s.m.s.DefaultHandlerExceptionResolver - Resolving exception from handler [public java.util.List<com.chaitanya.departmentHead.model.DepartmentHeadDTO> com.chaitanya.web.controller.DepartmentHeadController.getDepartmentHead(com.chaitanya.ajax.AjaxResponse)]: org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Unrecognized token 'pq_datatype': was expecting ('true', 'false' or 'null')
at [Source: java.io.PushbackInputStream@5af5c788; line: 1, column: 13]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'pq_datatype': was expecting ('true', 'false' or 'null')
at [Source: java.io.PushbackInputStream@5af5c788; line: 1, column: 13]
Controller:
@RequestMapping(value="/departmentHead",method=RequestMethod.POST,headers = "Accept=application/json", produces = "application/json")
public @ResponseBody List<DepartmentHeadDTO> getDepartmentHead(@RequestBody AjaxResponse receivedDepartmentHeadDTO){
List<DepartmentHeadDTO> departmentHeadDTOList = null;
LoginUserDetails user = (LoginUserDetails)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if(Validation.validateForNullObject(user.getLoginDTO().getEmployeeDTO())){
// departmentHeadDTOList = deptHeadSerrvice.findDepartmentHeadUnderCompany(receivedDepartmentHeadDTO);
}
return departmentHeadDTOList;
}
POJO class:
public class AjaxResponse {
Long id;
boolean success;
String message;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
Please help. Is there something i am missing in POST call.
Because I able make ajax call in my project from your inline grid.
-
Your dataModel does a POST back to controller but there is no getData function to get and set the data
-
Hi ali,
My controller is not accepting JSON which i am passing. I have tried too many combination of string.
@Admin,
The difference between this POST call from DataModel and AJAX call is we using "type" property in ajax and "method" property in data model.
Other than this there is no difference. still why this POST call is not working.
Please help.
-
Instead of
data: JSON.stringify(jsonToBeSend),
try
postData: JSON.stringify(jsonToBeSend),
-
Hi Ali,
I have also tried postData attribute. but not working.
When I removed the @requestbody attribute, my controller gets executed. but,
In the case of Get call Jackson converting JSON to Object but in the case of Post call, jackson could not able to convert to Object.
This might be JSON is not getting pass properly.
Normally when I make Post call ajax call from inline grid,
My URL is like: http://localhost:8085/ExpenseManagement/employee?{JSON Parameters}
But when I send Post call from child grid:
My URL is like http://localhost:8085/ExpenseManagement/employee?[here is invalid string]*pq_datatype=Json&_=4398787
I think there is different JSON format to send through the inner grid.
Note: Above Post call URL observe by changing it to "get"
-
Thanks @Ali for your effort,
Finally my controller and Jackson library works.
Below code worked:
getUrl: function() {
return { url: "/ExpenseManagement/departmentHead", data: "{\"branchId\":"+rowData.branchId+"}" };
},