Invalid JSNI method reference

1,814 views
Skip to first unread message

gbuchin

unread,
Mar 21, 2008, 1:59:32 PM3/21/08
to Google Web Toolkit
I have a function:

public static void messageBox( String sTitle, String sMessage )
{
Window.alert( sTitle + " | " + sMessage );
}

I am trying to call it from javaScript, but I can't seem to ge tthe
signature correct. I tried :

@com.ecopy.gwt.client.Utils::messageBox(Ljava/lang/String;,Ljava/lang/
String;);

but the compiler says "Expected a valid parameter type signature in
JSNI method reference"

Thoughts?

Adam T

unread,
Mar 21, 2008, 2:40:03 PM3/21/08
to Google Web Toolkit
Hi,

You don't need the comma in your JSNI param defn separating the two
Strings, i.e. you have:

@com.ecopy.gwt.client.Utils::messageBox(Ljava/lang/String;,Ljava/lang/
String;);

it should be

@com.ecopy.gwt.client.Utils::messageBox(Ljava/lang/String;Ljava/lang/
String;);

...but then you also need to provide the parameters, so it should be
something like:

@com.ecopy.gwt.client.Utils::messageBox(Ljava/lang/String;Ljava/lang/
String;)("String1","String2");


//Adam
Message has been deleted

Amit Sharma

unread,
Aug 29, 2012, 5:00:20 AM8/29/12
to google-we...@googlegroups.com, Google Web Toolkit, gbu...@mailcity.com
What if I want to pass Double value instead of String

mukarev

unread,
Aug 29, 2012, 7:01:29 AM8/29/12
to google-we...@googlegroups.com, Google Web Toolkit, gbu...@mailcity.com
if you have a method like

public void addDoubles(final double d1, final double d2){
...
}

you will do it like

@com.ecopy.gwt.client.Utils:: addDoubles(DD)(x,y); 

Steve C

unread,
Aug 30, 2012, 1:48:52 PM8/30/12
to google-we...@googlegroups.com, Google Web Toolkit, gbu...@mailcity.com
For the method you're using, you could make it more general-purpose:

public static void messageBox( String sTitle, Object message )
{
Window.alert( sTitle + " | " + message.toString() );
}


@com.ecopy.gwt.client.Utils::messageBox(Ljava/lang/String;,Ljava/lang/Object;)("TheTitle", 99.999);

And I believe that AutoBoxing will take care of the double-to-Double conversion, but haven't actually tested that.

Thomas Broyer

unread,
Aug 31, 2012, 5:56:32 AM8/31/12
to google-we...@googlegroups.com, Google Web Toolkit, gbu...@mailcity.com
AFAICT, it won't. You'd have to use @java.lang.Double::valueOf(99.999)
 
Reply all
Reply to author
Forward
0 new messages