Saturday, August 12, 2017

Accessing "basic" JS Object in JsInterop callback

Hi all,
I have recently started testing JsInterop for our GWT 2.8.1 application and I have encountered a situation I could not solve without using the old style JSNI approach.

Consider the following minimal JS library I would like to use in Java/GWT:

(function (window, document, undefined) {

function WatchDog(name) {
this._name = name;

WatchDog.prototype.register = function(callback) {
this._callback = callback;

WatchDog.prototype.broadcast = function(msg) {
if (this._callback) {
'name' : this._name,
'timestamp' : new Date().getTime(),
'msg' : msg

.Dummy = {
: function(name) {
return new WatchDog(name);

}(window, document));

Please note that the broadcast function passes a "basic" JS Object {} (i.e. without a specific prototype) to the callback function.

Here below my JsInterop mappings:

package xxx;

import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsType;

@JsType(isNative = true, namespace = JsPackage.GLOBAL)
public class Dummy {
private Dummy() {}
public static native WatchDog watchDog(String name);

package xxx;

import jsinterop.annotations.JsMethod;
import jsinterop.annotations.JsType;

@JsType(isNative = true)
public class WatchDog {
private WatchDog() {}
public native void register(Callback callback);
public native void broadcast(String msg);

package xxx;

import jsinterop.annotations.JsFunction;

public interface Callback {
void call(Object event);

In my Java code, when the callback function is invoked, the event parameter is an instance of

Without using JSNI I am not able to access/read the object's properties. Does JsInterop addresses this scenario without falling-back to old style JSNI?

Thanks a lot in andvance

You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment