Wednesday, June 29, 2022

Re: Using JsInterop to create JS object literals

Using isNative=true, you're telling GWT that you're only "mapping" in Java a type that exists in JS. The default naming rule is that the full name of that type is the fully qualified name of the Java class, you can change the simple name with 'name', and the prefix with namespace (which defaults to the package name for top-level classes, or the enclosing type's JS name for nested classes). So with namespace=GLOBAL but without the name="Object", you're saying that you want to basically do a 'new $wnd.MyPluginConfig()' in JS, and the browser rightfully complains that there's no such MyPluginConfig. Adding name="Object" means you'll do a 'new $wnd.Object()' in JS.

Fwiw, I'd rather user fields than getters/setters for such objects. YMMV.

On Wednesday, June 29, 2022 at 8:38:19 AM UTC+2 Nicolas Chamouard wrote:
Thank you !
It is a bit mysterious to me, but with name = "Object" the constructor works :)


Le mercredi 29 juin 2022 à 00:47:32 UTC+2, m.conr...@gmail.com a écrit :
try adding name = "Object" so that it uses an empty javascript Object as the wrapped item.

I found this via Googling:

@JsType(namespace = JsPackage.GLOBAL, isNative = true, name = "Object")  public class MyPluginConfig {      @JsProperty public void setXXXX(String str);      @JsProperty public String getXXXX();      ...  }

Ref: https://stackoverflow.com/a/36329387/12407701


On Tue, Jun 28, 2022 at 6:24 PM Nicolas Chamouard <ncham...@alara-group.fr> wrote:
Yes, it does not change anything : 

@JsType(isNative=true, namespace = JsPackage.GLOBAL)

public class OptionOverrides {


    @JsConstructor

    public OptionOverrides() {}

    

    @JsProperty

    public native String getInitialView();

    @JsProperty

    public native void setInitialView(String initialView);

}


Still the same error : $wnd.OptionOverrides is not a constructor


Le mardi 28 juin 2022 à 23:27:08 UTC+2, m.conr...@gmail.com a écrit :
Have you tried giving the class a constructor?


On Tue, Jun 28, 2022 at 4:04 PM Nicolas Chamouard <ncham...@alara-group.fr> wrote:
Hello,

I am using JsInterop to integrate FullCalendar to my GWT application.
As described here https://fullcalendar.io/docs/initialize-globals, I am supposed to create an object literal and pass it to the Calendar() constructor.

I have managed to create this class : 

@JsType(namespace = JsPackage.GLOBAL)

public class OptionOverrides {


    @JsProperty

    public native String getInitialView();

    @JsProperty

    public native void setInitialView(String initialView);

}

It works but the FullCalendar complains about all the Java Object stuff that is translated to javascript : equals(), hashCode(), etc

I have tried to add isNative=true to my class, but in this case i cannot instantiate it in Java (error : $wnd.OptionOverrides is not a constructor)

Is there an other way to do this, am I missing something here ?

Thanks



--
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 google-web-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit/a03c881a-48d4-4892-9fae-7719bc9a57b8n%40googlegroups.com.

--
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 google-web-tool...@googlegroups.com.

--
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 google-web-toolkit+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit/fa165911-5805-4315-843d-14d44f3a1fe2n%40googlegroups.com.

No comments:

Post a Comment