Re: To send and receive json array using ajax in Ofbiz
Hi lsy, Your message has been moderated. Please subscribe to the user ML for such questions and then use your email client See also why here http://ofbiz.apache.org/mailing-lists.html You will get a better support , it's more fair to share with everybody and people can answer you on the ML rather than directly to you The wider the audience the better the answers you might get Also it's more work for moderators who have to accept your messages as long as you have not subscribed. I'll personally no longer accept them (other moderators still could) Thanks Jacques Le 17/06/2019 à 19:58, lsy a écrit : It's been a month since I used Ofbiz. I want to use JSON Array sent from Ajax. How does JAVA handle this? 1. controller.xml 2. service.xml 3. crudList.ftl 4. service.java public static Map CRUDList(DispatchContext dctx, Map context) { Delegator delegator = dctx.getDelegator(); Map result = ServiceUtil.returnSuccess(); GenericValue userLogin = (GenericValue) context.get("userLogin"); List reqData = UtilGenerics.checkList(context.get("data")); String str = reqData.get(0); JSONArray data = new JSONArray(); data = new JSONArray(str); ... } **result = data.length ==> 1 When I take a JSONARray and size it, it's 1. I don't know why. I'd appreciate it if you could explain why. And then, Please let me know if there is an easier way to use Java by sending an arraylist to Ajax. -- Sent from: http://ofbiz.135035.n4.nabble.com/OFBiz-User-f135036.html
Re: To send and receive json array using ajax in Ofbiz
Hello, lsy writes: > It's been a month since I used Ofbiz. > I want to use JSON Array sent from Ajax. > How does JAVA handle this? > 1. controller.xml > > > > > > > > 2. service.xml > auth="true" > location="com.test.services.TestServices" invoke="CRUDList"> > optional="false"/> > optional="true"/> > > > 3. crudList.ftl > > > 4. service.java > public static Map CRUDList(DispatchContext dctx, Map ?> context) { > Delegator delegator = dctx.getDelegator(); > Map result = ServiceUtil.returnSuccess(); > GenericValue userLogin = (GenericValue) context.get("userLogin"); > > List reqData = UtilGenerics.checkList(context.get("data")); > String str = reqData.get(0); > JSONArray data = new JSONArray(); > data = new JSONArray(str); > > ... > } > > **result = data.length ==> 1 > When I take a JSONARray and size it, it's 1. > I don't know why. > I'd appreciate it if you could explain why. > And then, Please let me know if there is an easier way to use Java by > sending an arraylist to Ajax. Unless I am overlooking something, you simply need to associate the key “data” with the Java list you want to be converted to a JSON list like this: result.put("data", *the java list you want to be converted in JSON*); return result; The is supposed to convert the service result map (plus other things) to JSON auto-magically. -- Mathieu Lirzin GPG: F2A3 8D7E EB2B 6640 5761 070D 0ADE E100 9460 4D37