Pregunta

Estoy creando un envoltorio GWT alrededor de una biblioteca de JavaScript. Una de las funciones de JavaScript toma un objeto anónimo como su argumento por ejemplo:.

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

En el lado de Java ¿cómo puedo crear este tipo de objeto JavaScript y pasarlo a mi aplicación nativa?

Por el momento, en el lado de Java que tengo:

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

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

Cualquier punteros apreciados, gracias.

¿Fue útil?

Solución

Si usted sabe exactamente lo que se deben utilizar parámetros, puede hacer lo siguiente (quitar las nuevas líneas adicionales después ::)

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

un pequeño clip de la documentación 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";
  }-*/;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top