Ah, you mentioned that before but I don't think I understood. I'm not sure I do yet.
Are you suggesting that I use the "Live Connect" feature in which I would use the 'java' keyword to access java functions directly from JS? If that's the case I have two concerns that have thus far held me back from even enabling that feature. 1 - The scripts are untrusted, and live connect only seems to be safe if the scripts are trusted. 2 - I am presenting an API to the user (think of it like a web browsers DOM), forcing the users to learn about using a nonstandard keyword like 'java' would be significantly less than ideal for my use. Thanks Norris! David -----Original Message----- From: dev-tech-js-engine-rhino-bounces+davidparks21=yahoo....@lists.mozilla.org [mailto:dev-tech-js-engine-rhino-bounces+davidparks21=yahoo....@lists.mozill a.org] On Behalf Of Norris Boyd Sent: Monday, February 23, 2009 2:00 PM To: [email protected] Subject: Re: Not doing something right On Feb 23, 11:15 am, "David Parks" <[email protected]> wrote: > Thanks for the reply. I understand that the constructor is necessary for the > JS environment to create the object. But I already have the object created > and just want to add it to the JS environment. Either by adding a new > variable that references it or by returning a reference to it from a native > function call. Can you just use a plain Java object? Rhino will do the "right" thing and allow your JavaScript code to access the Java object. So for your example above, the class would simply be public class ExampleJSClass { public void f1() { } } --N > > Thanks! > Dave > > -----Original Message----- > From: > > dev-tech-js-engine-rhino-bounces+davidparks21=yahoo....@lists.mozilla.org > [mailto:dev-tech-js-engine-rhino-bounces+davidparks21=yahoo....@lists.mozill > a.org] On Behalf Of Mike Tardif > Sent: Monday, February 23, 2009 8:42 AM > To: [email protected] > Subject: Re: Not doing something right > > On Feb 20, 1:34 pm, "David Parks" <[email protected]> wrote: > > I'm either doing something wrong or don't understand the functionality of > > Rhino here. > > > I am creating an object in Java and trying to pass it to the JS > environment > > via another JS function. I set up this simplified example to try to > > understand the functionality: > > > Scriptable jsObject = Context.toObject(new ExampleJSClass(), > instanceScope); > > instanceScope.put("obj0", instanceScope, jsObject); > > cx.evaluateString(instanceScope, "obj0.fun1();", "test", 1, null); > > > static class ExampleJSClass extends ScriptableObject { > > public void jsConstructor(){ } > > public String getClassName(){ return "ExampleJSClass"; } > > public void jsFunction_fun1(){ } > > } > > > Can someone help me understand what I need to do to make this work, or > what > > I'm doing wrong? This example throws the exception: > > org.mozilla.javascript.EcmaError: TypeError: Cannot find default value for > > object. (test#1) > > It is my understanding that you need a ctor -- see below > > static class ExampleJSClass extends ScriptableObject { > public void jsConstructor(){ } > public void ExampleJSClass() { } // must match the signature of > your jfConstructor > public String getClassName(){ return "ExampleJSClass"; } > public void jsFunction_fun1(){ } > } > > Cheers, Mike > _______________________________________________ > dev-tech-js-engine-rhino mailing list > [email protected]https://lists.mozilla.org/listinfo /dev-tech-js-engine-rhino _______________________________________________ dev-tech-js-engine-rhino mailing list [email protected] https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino _______________________________________________ dev-tech-js-engine-rhino mailing list [email protected] https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
