JsInterop Question regarding execution in index.html

49 views
Skip to first unread message

Paul Mazzuca

unread,
Feb 13, 2017, 11:24:16 AM2/13/17
to GWT Users
I need to create a javascript function called "handleOpenUrl(url)" that will be called from a Cordova plugin (https://github.com/EddyVerbruggen/Custom-URL-scheme)  for a hand off from a mobile browser.  If I create the function inside my index.html, it is called successfully. The challenge is how do I move the execution into my GWT module?  

My ideas are...

1:  Somehow create a GWT method that is recognized in the global js namespace as "handleOpenUrl"?  I know method names get compiled out, so I am not sure how I would accomplish this.  

2.  Leave the handleOpenUrl inside the index.html, but somehow call a GWT method from that?

Any thoughts/ideas would be much appreciated.

Juan Pablo Gardella

unread,
Feb 13, 2017, 11:41:28 AM2/13/17
to GWT Users
You can use jsinterop

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

Paul Mazzuca

unread,
Feb 13, 2017, 12:02:00 PM2/13/17
to google-we...@googlegroups.com
Thanks for the quick reply.  This was my first inclination, which does not work.

@JsMethod(namespace = JsPackage.GLOBAL, name = "handleOpenUrl")

public void runMe(String url) {

    Window.alert("Success");

}



Perhaps, I am doing it wrong, but I had always thought the JsInterop wraps existing javascript. I am trying to declare a new javascript function in the global namespace so that a cordova plugin can call it.  handleOpenUrl does NOT exist, but I am responsible for creating it.


Below js code does work inside my index.html.  I need to emulate that is GWT.


function handleOpenURL(url) {

     alert("received url: " + url);

}




On Mon, Feb 13, 2017 at 8:41 AM, Juan Pablo Gardella <gardella...@gmail.com> wrote:
You can use jsinterop

On Mon, 13 Feb 2017 at 13:24 Paul Mazzuca <paul.j....@gmail.com> wrote:
I need to create a javascript function called "handleOpenUrl(url)" that will be called from a Cordova plugin (https://github.com/EddyVerbruggen/Custom-URL-scheme)  for a hand off from a mobile browser.  If I create the function inside my index.html, it is called successfully. The challenge is how do I move the execution into my GWT module?  

My ideas are...

1:  Somehow create a GWT method that is recognized in the global js namespace as "handleOpenUrl"?  I know method names get compiled out, so I am not sure how I would accomplish this.  

2.  Leave the handleOpenUrl inside the index.html, but somehow call a GWT method from that?

Any thoughts/ideas would be much appreciated.

--
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+unsub...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "GWT Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/ycAylgf11zo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-web-toolkit+unsub...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.

Juan Pablo Gardella

unread,
Feb 13, 2017, 12:10:41 PM2/13/17
to google-we...@googlegroups.com
Check if this flag is activated  -[no]generateJsInteropExports Generate exports for JsInterop purposes (defaults to OFF)


On Mon, 13 Feb 2017 at 14:01 Paul Mazzuca <paul.j....@gmail.com> wrote:
Thanks for the quick reply.  This was my first inclination, which does not work.

@JsMethod(namespace = JsPackage.GLOBAL, name = "handleOpenUrl")

public void runMe(String url) {

    Window.alert("Success");

}



Perhaps, I am doing it wrong, but I had always thought the JsInterop wraps existing javascript. I am trying to declare a new javascript function in the global namespace so that a cordova plugin can call it.  handleOpenUrl does NOT exist, but I am responsible for creating it.


Below js code does work inside my index.html.  I need to emulate that is GWT.


function handleOpenURL(url) {

     alert("received url: " + url);

}




On Mon, Feb 13, 2017 at 8:41 AM, Juan Pablo Gardella <gardella...@gmail.com> wrote:
You can use jsinterop

On Mon, 13 Feb 2017 at 13:24 Paul Mazzuca <paul.j....@gmail.com> wrote:
I need to create a javascript function called "handleOpenUrl(url)" that will be called from a Cordova plugin (https://github.com/EddyVerbruggen/Custom-URL-scheme)  for a hand off from a mobile browser.  If I create the function inside my index.html, it is called successfully. The challenge is how do I move the execution into my GWT module?  

My ideas are...

1:  Somehow create a GWT method that is recognized in the global js namespace as "handleOpenUrl"?  I know method names get compiled out, so I am not sure how I would accomplish this.  

2.  Leave the handleOpenUrl inside the index.html, but somehow call a GWT method from that?

Any thoughts/ideas would be much appreciated.

--
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 post to this group, send email to google-we...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "GWT Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/ycAylgf11zo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-web-tool...@googlegroups.com.

To post to this group, send email to google-we...@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-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.

Paul Mazzuca

unread,
Feb 13, 2017, 12:40:49 PM2/13/17
to google-we...@googlegroups.com

Thanks that worked! Given that this flag was off by default,  what are the main ramifications of leaving it on?

.....


The below code is successfully exported globally when the flag is on:



@JsMethod(namespace = JsPackage.GLOBAL, name = "handleOpenUrl")

public static void runMe(String url) {

  Window.alert("Success");

}


On Mon, Feb 13, 2017 at 9:09 AM, Juan Pablo Gardella <gardella...@gmail.com> wrote:
Check if this flag is activated  -[no]generateJsInteropExports Generate exports for JsInterop purposes (defaults to OFF)

On Mon, 13 Feb 2017 at 14:01 Paul Mazzuca <paul.j....@gmail.com> wrote:
Thanks for the quick reply.  This was my first inclination, which does not work.

@JsMethod(namespace = JsPackage.GLOBAL, name = "handleOpenUrl")

public void runMe(String url) {

    Window.alert("Success");

}



Perhaps, I am doing it wrong, but I had always thought the JsInterop wraps existing javascript. I am trying to declare a new javascript function in the global namespace so that a cordova plugin can call it.  handleOpenUrl does NOT exist, but I am responsible for creating it.


Below js code does work inside my index.html.  I need to emulate that is GWT.


function handleOpenURL(url) {

     alert("received url: " + url);

}




On Mon, Feb 13, 2017 at 8:41 AM, Juan Pablo Gardella <gardella...@gmail.com> wrote:
You can use jsinterop

On Mon, 13 Feb 2017 at 13:24 Paul Mazzuca <paul.j....@gmail.com> wrote:
I need to create a javascript function called "handleOpenUrl(url)" that will be called from a Cordova plugin (https://github.com/EddyVerbruggen/Custom-URL-scheme)  for a hand off from a mobile browser.  If I create the function inside my index.html, it is called successfully. The challenge is how do I move the execution into my GWT module?  

My ideas are...

1:  Somehow create a GWT method that is recognized in the global js namespace as "handleOpenUrl"?  I know method names get compiled out, so I am not sure how I would accomplish this.  

2.  Leave the handleOpenUrl inside the index.html, but somehow call a GWT method from that?

Any thoughts/ideas would be much appreciated.

--
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+unsub...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "GWT Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/ycAylgf11zo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-web-toolkit+unsub...@googlegroups.com.

To post to this group, send email to google-web-toolkit@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+unsub...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "GWT Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/ycAylgf11zo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-web-toolkit+unsub...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.

Jens

unread,
Feb 13, 2017, 3:07:50 PM2/13/17
to GWT Users

Thanks that worked! Given that this flag was off by default,  what are the main ramifications of leaving it on?


The flag is not active by default because your project might depend on GWT libraries that are also published as pure JS libraries by exporting the GWT code to JS using JsInterop (like you did). In that case all the exported classes/methods are considered entry points to your GWT app and the compiler has less opportunities to optimize any code that depends on it because it does not know how (and if) JS calls into your GWT app.

So basically if this option would be active by default, chances are that some projects compile to a larger final JS output because less optimizations have been done.

If you use newest GWT snapshot builds you can actually provide multiple regex to define which classes are allowed to be exported to circumvents the above issue. That way you can only export your own stuff and nothing from any library you might use. See: https://gwt-review.googlesource.com/#/c/17581/

-- J.
Reply all
Reply to author
Forward
0 new messages