Question

Je crée une enveloppe GWT autour d'une bibliothèque JavaScript. L'une des fonctions JavaScript prend un objet anonyme comme par exemple l'argument:.

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

Du côté Java comment puis-je créer ce type d'objet JavaScript et le transmettre à mon implémentation native?

À l'heure actuelle, du côté Java je:

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

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

Les pointeurs ont apprécié, merci.

Était-ce utile?

La solution

si vous savez exactement quels paramètres doivent être utilisés, vous pouvez effectuer les opérations suivantes (supprimer de nouvelles lignes supplémentaires après ::)

private native void buildTabs(TabConfiguration config) /*-{
        $wnd.NAMESPACE.lib.buildTabs({hide: 
                config.@com.yournamehere.TabConfiguration::
                getHide()(), 
                placeholder: 
                config.@com.yournamehere.TabConfiguration::
                getPlaceholder()()});
}-*/;

un petit clip de la documentation GWT :

public native void bar(JSNIExample x, String s) /*-{
    // Call instance method instanceFoo() on this
    this.@com.google.gwt.examples.JSNIExample::instanceFoo(Ljava/lang/String;)(s);

    // Call instance method instanceFoo() on x
    x.@com.google.gwt.examples.JSNIExample::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 = this.@com.google.gwt.examples.JSNIExample::myInstanceField;

    // Write instance field on x
    x.@com.google.gwt.examples.JSNIExample::myInstanceField = val + " and stuff";

    // Read static field (no qualifier)
    @com.google.gwt.examples.JSNIExample::myStaticField = val + " and stuff";
  }-*/;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top