JSInterop & @JsProperty overriding name

477 views
Skip to first unread message

Ümit Seren

unread,
Jul 29, 2015, 8:51:39 AM7/29/15
to GWT Contributors

I started to play around with JSInterop and GWT 2.8.0-SNAPSHOT.

Primarily I was following these documentation:

https://docs.google.com/document/d/1tir74SB-ZWrs-gQ8w-lOEV3oMY6u6lF2MmNivDEihZ4/edit#

However I ran into some issues regarding properties that don’t follow Java bean style convention (i.e. xAxisParser) .

According to the javaDocs on the @JsProperty annotation it should be possible to define properties also in this way : @JsProperty x(intx) which translates to this.x=y.
However when I try this, the compiler complains that the property doesn’t follow Java Bean naming conventions.

I found a recent post about overhaul of JsInterop’s annotations (https://groups.google.com/forum/#!searchin/google-web-toolkit-contributors/annotations/google-web-toolkit-contributors/Dwdk-aEHs8Y/OvSNe6egUekJ) and that it should be possible to
override the property name.

I was curious if this is planned for the 2.8.0 release or if this will go into GWT 3.0 ?

Currently my only workaround is to use JSNI: to set the property directly:

@JsType 
interface MyInterface {
   @JsProperty void setTitle(String title);
   @JsProperty String getTitle();

   void setXAxisParser(Callback callback);
}

public MyClass implements MyInterface {
     public String title;
     public Callback callback;

    @Override
     public void setTitle(String title) {
         this.title = title;
     }
     @Override
     public String getTitle() {
          return title;
     }
     @Override
     public void setXAxisParser(Callback callback)/*-{
         this.xValueParser = callback;
     }*-/;
}

Goktug Gokdogan

unread,
Jul 29, 2015, 3:11:58 PM7/29/15
to google-web-toolkit-contributors
On Tue, Jul 28, 2015 at 8:36 AM, Ümit Seren <uemit...@gmail.com> wrote:

I started to play around with JSInterop and GWT 2.8.0-SNAPSHOT.

Primarily I was following these documentation:

https://docs.google.com/document/d/1tir74SB-ZWrs-gQ8w-lOEV3oMY6u6lF2MmNivDEihZ4/edit#

However I ran into some issues regarding properties that don’t follow Java bean style convention (i.e. xAxisParser) .

According to the javaDocs on the @JsProperty annotation it should be possible to define properties also in this way : @JsProperty x(intx) which translates to this.x=y.


The javadoc is not accurate, only bean convetions is supported at the moment.
 

However when I try this, the compiler complains that the property doesn’t follow Java Bean naming conventions.

I found a recent post about overhaul of JsInterop’s annotations (https://groups.google.com/forum/#!searchin/google-web-toolkit-contributors/annotations/google-web-toolkit-contributors/Dwdk-aEHs8Y/OvSNe6egUekJ) and that it should be possible to
override the property name.

I was curious if this is planned for the 2.8.0 release or if this will go into GWT 3.0 ?


It is planned for 2.8 release.
 

Currently my only workaround is to use JSNI: to set the property directly:

@JsType 
interface MyInterface {
   @JsProperty void setTitle(String title);
   @JsProperty String getTitle();

   void setXAxisParser(Callback callback);
}

public MyClass implements MyInterface {
     public String title;
     public Callback callback;

    @Override
     public void setTitle(String title) {
         this.title = title;
     }
     @Override
     public String getTitle() {
          return title;
     }
     @Override
     public void setXAxisParser(Callback callback)/*-{
         this.xValueParser = callback;
     }*-/;
}

--
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit-contributors/64db778c-7fca-45b7-a0c8-52aae0c6968f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ümit Seren

unread,
Jul 30, 2015, 5:49:26 AM7/30/15
to GWT Contributors, gok...@google.com
Thanks for the heads up. 

One additional question. I am trying to wrap a 3rd javascript library that is relying on `hasOwnProperty` to check if the object contains a specific property. 
As far as I can tell the @JsProperty will create a property using `defineProperty`. 
Is there any way how to avoid the "automatic" creation of the property (or is anything planned?) 
Currently my workaround is to use JSNI for those fields. 

Ümit Seren

unread,
Jul 30, 2015, 7:15:12 AM7/30/15
to GWT Contributors, gok...@google.com, uemit...@gmail.com
ok sorry,
 forget what I said. It actually works fine, when I take the approach that is described in the google docs. 

Paul Stockley

unread,
Jul 30, 2015, 10:01:04 AM7/30/15
to GWT Contributors, gok...@google.com, uemit...@gmail.com
Is there a better idea of exactly what Js Interop will look like when 2.8 is released. The document referenced above was last updated on Sept 2014. From this proposal, what will and wont make it into 2.8. This whole area has become very confusing with all the changes in direction that seem to be happening. 

Goktug Gokdogan

unread,
Jul 30, 2015, 2:27:38 PM7/30/15
to Paul Stockley, GWT Contributors, uemit...@gmail.com
Most of the direction changes are presented and discussed in the contributor group but it is not well formed as a document. Before 2.8, the document will be updated with the latest info. This is still a work in progress, we are making sure what will be available with  jsinterop will be inline with future directions we are taking with the SDK.

Wesley, Wookjin Jung

unread,
Aug 2, 2015, 1:26:17 AM8/2/15
to GWT Contributors, uemit...@gmail.com
Appreciate you guys passion and effort!!

Ümit Seren

unread,
Aug 9, 2015, 8:47:46 AM8/9/15
to GWT Contributors
One more issue that came up. 

I have a @JsType interface and @JsProperty fields and a class that implements it with public fields and getters/setters. 
This works fine in DevMode and when compiling with draftCompile = true

However as soon as I do a normal production compile the fields get obfuscated and renamed. 
Is this a known issue ? 



On Wednesday, July 29, 2015 at 9:11:58 PM UTC+2, Goktug Gokdogan wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-contributors+unsubscribe@googlegroups.com.

Goktug Gokdogan

unread,
Aug 11, 2015, 3:13:29 PM8/11/15
to google-web-toolkit-contributors
From your description if looks like you are trying following:

interface SomeJsInteface {
  @JsProperty String getName();
}

class SomeObject implements SomeJsInterface {
  public String name;
  public String getName() { return name; }
}

Making name field 'public' here is not really a solution. We need to implement overriding of JsProperty properly. You need to wait little bit longer for that.

You may work around this by making SomeObject a JsType but compiler my complain about name conflict; you need to give it a try.

To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-co...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit-contributors/89f59140-ed1b-4461-9386-2cf0a1861d99%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages