0

I'm creating a GWT wrapper round a JavaScript library. One of the JavaScript functions takes an anonymous object as its argument e.g.:

obj.buildTabs({ hide: true, placeholder: 'placeholder' });

On the Java side how do I create this type of JavaScript object and pass it to my native implementation?

At the moment, on the Java side I have:

public void buildTabs(TabConfiguration config) {
   // ?
}

private native void buildTabs(?) /*-{
        $wnd.NAMESPACE.lib.buildTabs(?);
}-*/;

Any pointers appreciated, thanks.

1 Answer 1

2

if you exactly know what parameters should be used, you can do the following (remove additional new lines after ::)

private native void buildTabs(TabConfiguration config) /*-{
        $wnd.NAMESPACE.lib.buildTabs({hide: 
                [email protected]::
                getHide()(), 
                placeholder: 
                [email protected]::
                getPlaceholder()()});
}-*/;

a small clip from the GWT documentation:

public native void bar(JSNIExample x, String s) /*-{
    // Call instance method instanceFoo() on this
    [email protected]::instanceFoo(Ljava/lang/String;)(s);

    // Call instance method instanceFoo() on x
    [email protected]::instanceFoo(Ljava/lang/String;)(s);

    // Call static method staticFoo()
    @com.google.gwt.examples.JSNIExample::staticFoo(Ljava/lang/String;)(s);

    // Read instance field on this
    var val = [email protected]::myInstanceField;

    // Write instance field on x
    [email protected]::myInstanceField = val + " and stuff";

    // Read static field (no qualifier)
    @com.google.gwt.examples.JSNIExample::myStaticField = val + " and stuff";
  }-*/;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.