Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Java array in applet

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I've created an applet that communicates with client/server java code. I now want to pass my results back to the applet. In the Java client I have an array (of strings) that I pass to the applet. However, over in the applet when I read the array I passed from the Java Client, all I get is an array that represents the first string element in the java array.
Java Client Code Snippet

/* java script function called by the Java client */

When I pop up my alert window, the printout I get is the following:
[0] = 'j'
[1] = 'o'
[2] = 'e'
and that's it. I'm thinking that this may have something to do with the fact that I am passing a string array. Has anyone worked with passing string arrays from Java to Javascript. Any assistance will be appreciated.
Joe Crew
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Joe,
According to the API the following:
public Object call(String methodName, Object args[])
Calls a JavaScript method. Equivalent to "this.methodName(args[0], args[1], ...)" in JavaScript.
which is consistent with what you are describing. I think you need to pass a single object instead of an array. You might try something like a delimited string and then change it inside your script method...
Regards,
Manfred.
 
Joe Crew
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Manfred for the advice. I too was thinking I may have to send a string back, but I really don't want to have to write a parser in javascript even though I may have to anyway. The string I would have to pass will be a nasty one. Quoted text, all number types (int, float etc), ANY character is valid, and I mean any because this will be an i18n product. Then inside a quoted string there can be nested quotes nested many times over. Don't get me wrong, I've already written this parser in Java for the Server side database because I pass it from the applet as a string in the first place. I just didn't want to write it again in js if I could just pass is as an array. Having to parse it will be slower than just passing an array and updating the DOM variables. Well I could just pass the string to the applet and in the JS call my Java parsing routine. I wonder .....
Joe Crew
 
Mo-om! You're embarassing me! Can you just read a tiny ad like a normal person?
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic