send request body with parameters in ODataV4Adaptor (adapters)

hi,

i am making server call using DataManager adapter(ODataV4Adaptor). i need to send request body along with parameters in that server call.
how to send request body in adapters.

i am already sending parameters as shown below and it is working fine. so ineed to send request body aswell

below is my sample code: server side

 @GetMapping("/getlookupvalues")
    public RequestResponse getReferenceColumnValues(@SessionAttribute(ApplicationPropertiesUtil.curSolID) Integer solutionId,
                                                    @SessionAttribute(ApplicationPropertiesUtil.curUserID) Integer userId,
                                                    @SessionAttribute(ApplicationPropertiesUtil.curOrgID) Integer orgId,
                                                    @RequestParam(value = "versionNo") Integer versionNo,
                                                    @RequestParam(value = "entityViewUuId") String entityViewUuId,
                                                    @RequestParam(value = "columnUuId") String columnUuId,
                                                    @RequestParam(value ="columnLookupUuid") String columnLookupUuid,
                                                    @RequestBody(required = false) ColumnLookupDependentValues columnLookupDependentValues,
                                                    @RequestParam(value ="businessDate", required = false) Integer businessDate) {
        LOGGER.info("EXEFLOW -> RefDataManagementController -> getReferenceColumnValues()");
        RequestResponse response = new RequestResponse();
        Map<String, Object> model = new HashMap<>();

....some logic....
}

below is my UI code

let dropDownValues=[];
              this.gridInstance.showSpinner();
              new DataManager({
                adaptor: new ODataV4Adaptor,
                crossDomain: true,
                url: `http://localhost:8081/data-management-service/dm/getlookupvalues?versionNo=`+versionNo
                +`&entityViewUuId=`+entityViewUuid+`&columnUuId=`+column.columnUuid+`&columnLookupUuid=`+column.columnLookupUuid
             }).executeQuery(new Query()).then((result=> {
              this.gridInstance.hideSpinner();
                result.actual.model.columnValues.forEach((col=> {
                  let dpObj = {};
                  dpObj[column.columnName + "_id"] = col;
                  dpObj[column.columnName + "_name"] = col;
                  dropDownValues.push(dpObj);
                });
             })

5 Replies 1 reply marked as answer

SM Shalini Maragathavel Syncfusion Team March 19, 2021 11:24 AM UTC

Hi Venkatesh, 

Thanks for contacting Syncfusion support. 

Based on your query you have mentioned that you need to send request body along with parameters in server call. So, before we proceed with your query we need the following details, 

1. In this request body means that you need to some JSON data or XML data to the server? Please explain more information on your query. 

2. We checked the attached code example and found that you have send some values in the URL. So, do you need to access this values in the server side method? 

3. Syncfusion Package Version. 

Regards,
Shalini M. 



VB Venkatesh Babu S N March 23, 2021 10:55 AM UTC

hi,

1.i need to send the json object in the requestbody to the server
2.i am sending some values in the url and i am able to access those values in server side method. along with those values i need to send one more jsonobject in request body(ColumnLookupDependentValues  is the value in server side. please check server side method posted in previous query).
3.syncfusion package version is 18.4.39



SM Shalini Maragathavel Syncfusion Team March 26, 2021 01:35 PM UTC

Hi Venkatesh,

Thanks for contacting Syncfusion support.

Based on your requirement we suspect that you need to send JSON data to the server along with the service url. You can achieve your requirement using addParams Method of query class as demonstrated in the below code snippet,    
 


export default class App extends React.Component<{}, {}>{ 
public data = new DataManager({ 
    adaptor: new ODataAdaptor, 
    url: 'https://js.syncfusion.com/demos/ejServices/Wcf/Northwind.svc/Orders/' 
}); 
  public jsonData = [{ id: 1, text: 'data' }] 
public query = new Query().addParams('additional', JSON.stringify(jsonData)); 
public render() { 
    return <GridComponent dataSource={this.data} query={this.query}> 
            <ColumnsDirective> 
                <ColumnDirective field='OrderID' headerText='Order ID' width='120' textAlign="Right"/> 
                <ColumnDirective field='CustomerID' headerText='Customer ID' width='150'/> 
                <ColumnDirective field='ShipCity' headerText='Ship City' width='150'/> 
                <ColumnDirective field='ShipName' headerText='Ship Name' width='150'/> 
            </ColumnsDirective> 
           </GridComponent> 

controller.cs 

public IQueryable<Book> Get() 
        { 
            var queryString = Request.Query; 
            var data = queryString["additional"]; 
            return _db.Books; 
        } 



Screenshot:





You can get the sent additional JSON data in the Get() method at your controller. 

Please get back to us, if you need any further assistance. 


Regards,
Shalini M.
 



Marked as answer

VB Venkatesh Babu S N April 7, 2021 01:08 PM UTC

hi shalini,

if I use addParams Method of query class as demonstrated in the previous reply, the json object going as normal parameter along with url
but that is not my requirement.

my requirement is to send Map as a requestbody in rest call to java layer from UI using DataManager



 @GetMapping("/getlookupvalues")
    public RequestResponse getReferenceColumnValues(@SessionAttribute(ApplicationPropertiesUtil.curSolID) Integer solutionId,
                                                    @SessionAttribute(ApplicationPropertiesUtil.curUserID) Integer userId,
                                                    @SessionAttribute(ApplicationPropertiesUtil.curOrgID) Integer orgId,
                                                    @RequestParam(value = "versionNo") Integer versionNo,
                                                    @RequestParam(value = "entityViewUuId") String entityViewUuId,
                                                    @RequestParam(value = "columnUuId") String columnUuId,
                                                    @RequestParam(value ="columnLookupUuid") String columnLookupUuid,
                                                    @RequestBody(required = false) ColumnLookupDependentValues columnLookupDependentValues,
                                                    @RequestParam(value ="businessDate", required = false) Integer businessDate) {
        LOGGER.info("EXEFLOW -> RefDataManagementController -> getReferenceColumnValues()");
        RequestResponse response = new RequestResponse();
        Map<String, Object> model = new HashMap<>();

....some logic....
}


if you observe above java code, "getlookupvalues" is a rest call.
i am sending all the parameters from UI as shown below

new DataManager({
                adaptor: new ODataV4Adaptor,
                crossDomain: true,
                url: `http://localhost:8081/data-management-service/dm/getlookupvalues?versionNo=`+versionNo
                +`&entityViewUuId=`+entityViewUuid+`&columnUuId=`+column.columnUuid+`&columnLookupUuid=`+column.columnLookupUuid
             }).executeQuery(new Query()).then((result=> {
              this.gridInstance.hideSpinner();
                result.actual.model.columnValues.forEach((col=> {
                  let dpObj = {};
                  dpObj[column.columnName + "_id"] = col;
                  dpObj[column.columnName + "_name"] = col;
                  dropDownValues.push(dpObj);
                });
             })

and i can read those parameters in backend aswell.

but i have requestbody called "columnLookupDependentValues" in that rest call which contains a Map<String, String> object.

how to send that object to that rest call? 





TS Thiyagu Subramani Syncfusion Team April 14, 2021 10:20 AM UTC

Hi Venkatesh, 

Thanks for your update and sorry for the delay. 

Based on your requirement you want to send and read the RequestParam and RequestBody references. In previous update you have mentioned that you need to sending parameters using RequestParam and it is working fine but you need to send request body as well (@RequestBody).  

In your shared code required requestbody called "columnLookupDependentValues" in that rest call which contains a Map<String, String> object.  To achieve this requirement we suggest you to stringify that columnLookupDependentValues and  send to the server side using @RequestBody.You will get that stringify value from server side now you have to handle the deserialization (parse that stringify value ) by your own to get it and access as per your needs. 

Please get back to us, if you need any further assistance. 

Regards, 
Thiyagu S 


Loader.
Up arrow icon