Author Topic: Fetching data issue in nested grid through Spring controller,  (Read 5299 times)

Chaitanya21

  • Newbie
  • *
  • Posts: 17
    • View Profile
Fetching data issue in nested grid through Spring controller,
« on: February 23, 2017, 12:01:28 pm »
My child grid data model is like:
Code: [Select]
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:

Code: [Select]
/*  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:
Code: [Select]
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:
Code: [Select]
@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:
Code: [Select]
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.

ali

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Fetching data issue in nested grid through Spring controller,
« Reply #1 on: February 25, 2017, 09:02:51 pm »
Your dataModel does a POST back to controller but there is no getData function to get and set the data

Chaitanya21

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Fetching data issue in nested grid through Spring controller,
« Reply #2 on: February 25, 2017, 11:42:47 pm »
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.

ali

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Fetching data issue in nested grid through Spring controller,
« Reply #3 on: February 26, 2017, 02:11:51 pm »
Instead of

data: JSON.stringify(jsonToBeSend),

try

postData: JSON.stringify(jsonToBeSend),

Chaitanya21

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Fetching data issue in nested grid through Spring controller,
« Reply #4 on: February 28, 2017, 06:56:48 pm »
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"



Chaitanya21

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Fetching data issue in nested grid through Spring controller,
« Reply #5 on: February 28, 2017, 08:36:24 pm »
Thanks @Ali for your effort,

Finally my controller and Jackson library works.

Below code worked:

Code: [Select]
getUrl: function() {
                        return { url: "/ExpenseManagement/departmentHead", data: "{\"branchId\":"+rowData.branchId+"}" };
                    },