Wednesday, January 25, 2012

Re: Calling instance method from JSNI code

public void setName(String value) {
       Window.alert("setName");
}

Needs to be static. Remove the this. reference from the JSNI to call it.

Regards,

Alfredo

On Wed, Jan 25, 2012 at 12:25 PM, Maxim Schäfner <maxim.schaefner@ewetel.net> wrote:
Hi,
i'm trying to call an instance java method from a JSNI method like
decriped in GWT JSNI documentation.
But somehow I'm still getting exceptions:
My code:

public void bla() {
       jsni_method(JavaScriptObject event);// event is an dropEvent,
but that doesn't matter
}

public static native void jsni_method(JavaScriptObject event) /*-{
       alert('alert1');
       var name = @com.company.MyClass::getName(Lcom/google/gwt/core/
client/JavaScriptObject;)(event);
       alert(name);
       this.@com.company.MyClass::setName(Ljava/lang/String;)(name
+""); // doesn't matter if with added quotes ""
       alert('alert2');
}-*/;

public static native String getName(JavaScriptObject event) /*-{
       var n = 'jkkjkjhjjh';
       alert(n);
       return n;
}-*/;

public void setName(String value) {
       Window.alert("setName");
}

-----
I'm getting the following:
alert('alert1');
alert('jkkjkjhjjh');
alert(name); //name = jkkjk..
and then:
com.google.gwt.event.shared.UmbrellaException: One or more exceptions
caught, see full set in UmbrellaException#getCauses
       at
com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:
129)
       at com.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:129)
       at
com.google.gwt.event.dom.client.DomEvent.fireNativeEvent(DomEvent.java:
116)
       at com.google.gwt.user.client.ui.Widget.onBrowserEvent(Widget.java:
177)
       at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1351)
....
and
Caused by: java.lang.ClassCastException
       at java.lang.Class.cast(Class.java:2990)
       at com.google.gwt.dev.shell.JsValueGlue.get(JsValueGlue.java:169)
       at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:
57)
       at
com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:
172)
       at
com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:
337)
       at
com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:
218)

--------------------

What's the problem?
Thanks.

Regards, Max

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.




--
Alfredo Quiroga-Villamil

AOL/Yahoo/Gmail/MSN IM:  lawwton


--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment