jQWidgets Forums
jQuery UI Widgets › Forums › Plugins › Data Adapter › REST JSON List Parameters
This topic contains 4 replies, has 2 voices, and was last updated by userbob 10 years, 12 months ago.
-
Author
-
Hi,
I am posting/getting a request using the dataadapter.
This data entry needs to be a some kind of array to be picked up by a restful java service at the back end which looks like this
@GET @Path("/messageType") public SimpleValueList<String> get(@QueryParam("receiverCode") List<String> receiverCode, @QueryParam("senderCode") List<String> senderCode) { return new SimpleValueList<String>(data.getMessageTypes(receiverCode, senderCode)); }
You can ignore the return type and so on, the important piece is the query param
If I have this on the send then it works for one value
source = { url : '/messageType', type : 'GET', datatype : 'json', contentType: 'application/json', data : { 'receiverCode' : 'a', 'senderCode' : 'b' } datafields : [ { name : 'value' } ] };
I can get it to sort of work with the following on the data
‘receiverCode’ : $.param([{name : ‘receiverCode’, value : ‘5016237030227’},{name : ‘receiverCode’, value : ‘5012648000002’}]),
‘senderCode’ : $.param([{name : ‘senderCode’, value : ‘5016237030227’},{name : ‘senderCode’, value : ‘5012648000002’}])However when inspecting the list on the server i get one entry in each list which contains the following
[receiverCode=5016237030227&receiverCode=5012648000002]
I appreciate this is probably at the jquery level but can you give me a hint?
Regards,
Richard
Hi Richard,
This should not work. Your data object is expected to be a JSON object or String. jQuery will turn your JSON object to String using $.param, but on your side, it seems that you try to do it twice for some reason. It’s however, not necessary.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/Hi thanks for the reply so for me to receive a list on the server side would I have to do this?
data : { 'receiverCode' : ['a','b'], 'senderCode' : ['1','2'] }
I have tried every combination now, moving from GET to POST and trying to get a list to show up on the server
If I use Postman then this is perfectly acceptable
["5016237030227","5016237030227"]
However I cannot seem to get the following to work
data = ["5016237030227", "5012648000002"];
which results in a payload (for POST) of
0=5016237030227&1=5012648000002
Or
data = {loggedInAs:["5016237030227", "5012648000002"]}
which results in a payload of
loggedInAs%5B%5D=5016237030227&loggedInAs%5B%5D=5012648000002
in other words it puts the [] after each entry?
Thanks for your assistance but this is driving me insane, I can only assume it is all due to various uses of traditional and the $.param functions
I finally got this working by overriding the underlying ajax component to parse params traditionally
$.ajaxSetup({ traditional:true });
This puts out the json on the params as I expected and as RESTEasy required
loggedInAs=5055037200003&loggedInAs=5015715444440&loggedInAs=5016237030227
The data call was like this where loggedInAs
data = {'loggedInAs' : ['somevalue', 'somevalue2']}
I hope this helps someone as I spent a couple of days on this very very minor issue
-
AuthorPosts
You must be logged in to reply to this topic.