Friday, February 15, 2019

Re: Is it possible to mark a class as @JsType native without explicit annotation?

Ok,
just for posterity...

I managed to add jsinterop jars as dependencies. Then I had to change my simple POJO to be jsinterop compatible.
I didn't want to update all call sites but I had to do it anyway (due to constructor changes). If there is a better way let me know.

I thought about @JsProperty but this is also a server side class and it wouldn't work server side. Am I right on this?

Here are the changes:
- Constructor with arguments --> @JsOverlay static factory method
- getters/setter --> @JsOverlay, final

Before:
-----------------------
public class MyClass {
    private String id;

   public MyClass(String id) {
        this.id = id;
   }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}

After:
-------------------------
@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object")
public class MyClass {
    private String id;

  @JsOverlay
   public static create(String id) {
        final MyClass myClass = new MyClass();
        myClass.setId(id);
  }

   @JsOverlay
    public final String getId() {
        return id;
    }

   @JsOverlay
    public final void setId(String id) {
        this.id = id;
    }
}



On Fri, Feb 8, 2019 at 5:09 PM Vassilis Virvilis <vasvir2@gmail.com> wrote:
I thought so...

Nevertheless thanks for answering so swiftly.

   Vassilis

On Fri, Feb 8, 2019 at 5:07 PM Jens <jens.nehlmeier@gmail.com> wrote:

Does that capability exists somehow?

No. You have to create your own class, mark it as JsType and delegate to the class you don't own.

-- J. 

--
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 post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.


--
Vassilis Virvilis


--
Vassilis Virvilis

--
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 post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment