1

Using the scripting framework (javax.script.*), it's really easy to get basic integration between Java and Javascript working. However, once you get to the point of wanting to do something really useful, you run into all the little ways that the bridge from Javascript back to Java (and, to some extent, the other direction too) are messy.

Example: if you've got a Javascript object set up to implement a Java interface (which is basically easy to do), and one of the methods you want to implement needs to return an array of strings, you can't just do this:

 // ...
 return [ firstString, "hello world", lastString ];

That won't work because Javascript arrays aren't automatically converted to Java arrays. You have to explicitly construct a Java array with reflection, fill it up, and return that.

There are several irritating things like that, and none of them are hard to deal with, really, but as I'm now starting in on the second project that needs those tools I wonder whether this has been solved by some simple Javascript "bridge" framework designed for this purpose. I've found nothing useful via google searches (mostly because any search with the term "java" in it results in a billion hits), but there are people here who seem to know everything so I thought I'd ask.

asked Jul 4, 2010 at 17:57

1 Answer 1

1

One way that you can help the problem is using one of the two answers here. I've successfully gotten the Java based solution to work with variables.

The second one can easily be adapted into a JS util function. IE

 return toJavaArray(["something",1]);
answered Jul 4, 2010 at 20:39
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer! I've seen those, and I agree that it's pretty easy to create a utility Javascript routine. What I'm hoping, however, is that some smarty out there has already put together a library containing a bunch of just such a variety of utilities.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.