6

I'm trying to get every value from an 'application' object (in javascript using jquery) which has mostly Strings and booleans properties, but also a List. I want to get it on my server-side, java.

Here what I do to get the Strings and boolean :

Javascript with REST :

requete = clientRestApplication.saveApplication.read(application.id, application);
            requete.done();

application is my object of course. It contains an Array called mails filled with Strings.

@RequestMapping(value = "/enregistrerApplication/id/{id}", method = RequestMethod.GET)
@ResponseBody
public void EnregistrerApplication(@PathVariable Long id, String nom, String acronyme, Integer idWebGD, Boolean estProgressWindows,
                                    Boolean estProgressUnix, Boolean estDelphi, String cheminPatchWin, String cheminPatchUnix,
                                    String cheminOutilsCompileWin, String cheminOutilsCompileUnix,  String serveurCVS, String loginCVS, 
                                    String mdpCVS, boolean versionEncours, ArrayList<String> mails) { ... }

From here I can use every single attributes to do what I want, but can't get my array by any mean...

I'm probably doing something wrong, can somebody help ? Thanks a lot.

ToyToy
  • 83
  • 6

1 Answers1

1

Make your Java part return JSON. Convert your Jaava Array to JSON: Convert normal Java Array or ArrayList to Json Array in android

And process this JSON from the Javascript/JQuery side.

EDIT Reverse: Get JSON and converts into a Java Array : How to parse a JSON and turn its values into an Array?

Community
  • 1
  • 1
3pic
  • 1,188
  • 8
  • 26
  • Thanks for the answer : I'm pretty new at this actually and a little bit lost. I don't have JSONArray available, therefore I assume I need to add it to my project somehow... But are you sure you understood my question ? I need to get an array from javascript to java, not the reverse. – ToyToy Jul 23 '15 at 12:17
  • @Toy But your question is different . You asked question like JAVA to JAVASCRIPT ? Pls check it. – Human Being Jul 23 '15 at 12:48
  • 1
    @ToyToy JSON is perfectly the bridge for Java==>Javascript. But the same reversed way. In Java, receive JSON and make it a Java Array. Answer is here : http://stackoverflow.com/questions/2255220/how-to-parse-a-json-and-turn-its-values-into-an-array – 3pic Jul 23 '15 at 12:54
  • 1
    Thanks a lot, I finally managed to fix my problem and in the meantime understand what JSON do ! javascript side : var temp = JSON.stringify(application.mails); application.mails = temp; var requete1 = clientRestApplication.saveApplication.read(application.id, application); Java side : JSONArray jsa; jsa = new JSONArray(mails); for (int i=0; i – ToyToy Jul 27 '15 at 08:07
  • Welcome in the JSON world. You probabably will use it a lot on many projects. – 3pic Jul 27 '15 at 08:24