Hi all. I'm trying to create a java API for a JavaScript function that can 
accept variable number of parameters, for ex. trigger("eventName", param1, 
param2, ...). 

In java the desired java method signature, do not need to use java varargs, 
could be simple something like this:

public static final native void trigger(String eventName, Object[] params)/*-{
        ///$wnd.mylib.trigger(eventName, ....)
}-*/;


The thing is that the params array elements can be of any and mixed types. 
Could be POJOS or JavaScriptObject or java.lang.Integer. 

My problem with this is that I don't know how to create a JsArray or a native 
JavaScript array and put all the elements of parameter object[]params. 

I tried doing this in java using a JsArray and JsArrayMixed but elements must 
be casted to JavaScriptObject, and when doing so I get a "java.lang.Object 
cannot cast to com...JavaScriptObject" exception. This happens when trying to 
push an element into the jsarray: it need to be casted for java compiler: 
jsArray1.push((JavaScriptObject) myJavaArray[i]);

I also tried doing it in jsni javascript code, but I don't know how to access 
java arrays for obtaining its elements. The documentation says that from 
javascript java arrays are "opaque" objects. It also says :

"Although Java arrays are not directly usable in JavaScript, there are some 
helper classes that efficiently achieve a similar effect: JsArray,..... These 
classes are wrappers around a native JavaScript array."

But I think in my case, if I need to access a java array with java objects 
these classes have not use... ?

I think I'm missing something here... IMHO it is a common javascript technic 
defining functions with variable parameters ,and it sould be available to work 
with these from java using GWT JSNI. -

Any suggestion is mmost appreciated. Thanks in advance. 

-- 
Sebastian Gurin <sgu...@softpoint.org>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to