Re: Understanding JsInterop

2018-02-21 Thread Paul Stockley
Try using Js.uncheckedCast from jsinterop-base

On Tuesday, February 20, 2018 at 1:59:44 PM UTC-5, Scott Shumway wrote:
>
> I'm still unable to do this. I want to be able to get a DOMRect from a 
> com.google.gwt.dom.client.Element with JsInterop. If I cast to this Element 
> class, or even ((HasGetBoundingClientRect) (Object) element), I will get a 
> (runtime) java.lang.ClassCastException. The cast to Object works, of 
> course, it's the cast to HasGetBoundingClientRect.
>

-- 
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+unsubscr...@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.


Re: Understanding JsInterop

2018-02-20 Thread Scott Shumway
I'm still unable to do this. I want to be able to get a DOMRect from a 
com.google.gwt.dom.client.Element with JsInterop. If I cast to this Element 
class, or even ((HasGetBoundingClientRect) (Object) element), I will get a 
(runtime) java.lang.ClassCastException. The cast to Object works, of 
course, it's the cast to HasGetBoundingClientRect.

-- 
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+unsubscr...@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.


Re: Understanding JsInterop

2018-02-15 Thread Scott Shumway
Thanks! I didn't think of casting to Object first... I'll give it a try. I 
generally turn on as many compiler warnings as I can stand to get my code 
to compile through a strict filter, but I was getting outright errors.

Also, namespace with "Element", Doh! of course...

On Thursday, February 15, 2018 at 2:10:21 AM UTC-8, Thomas Broyer wrote:
>
>
>
> On Thursday, February 15, 2018 at 11:01:41 AM UTC+1, Vassilis Virvilis 
> wrote:
>>
>> Amazing trick!
>>
>> Obvious if you think about it - but very difficult to think it initially 
>> (for us mere mortals).
>>
>
> Well, when you write "element.getBoundingClientRect" in JS (without the 
> parenthesis), this is exactly what you're doing: getting a reference to the 
> function.
> In JS, if you call it later, you need to either use .call(element) or 
> .apply(element) to setup the appropriate 'this' element, or you first need 
> to .bind(element) it to the element. I'm not sure how JsInterop works in 
> this case, maybe (probably) my second example wouldn't actually work as it 
> does neither of these (you could use an element2.core.Function to 
> .call()/.apply() or .bind()).
>
> That being said, I didn't came with this pattern by myself either, I 
> believe I saw it somewhere in GWT's emulation library.
>

-- 
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+unsubscr...@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.


Re: Understanding JsInterop

2018-02-15 Thread Thomas Broyer


On Thursday, February 15, 2018 at 11:01:41 AM UTC+1, Vassilis Virvilis 
wrote:
>
> Amazing trick!
>
> Obvious if you think about it - but very difficult to think it initially 
> (for us mere mortals).
>

Well, when you write "element.getBoundingClientRect" in JS (without the 
parenthesis), this is exactly what you're doing: getting a reference to the 
function.
In JS, if you call it later, you need to either use .call(element) or 
.apply(element) to setup the appropriate 'this' element, or you first need 
to .bind(element) it to the element. I'm not sure how JsInterop works in 
this case, maybe (probably) my second example wouldn't actually work as it 
does neither of these (you could use an element2.core.Function to 
.call()/.apply() or .bind()).

That being said, I didn't came with this pattern by myself either, I 
believe I saw it somewhere in GWT's emulation library.

-- 
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+unsubscr...@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.


Re: Understanding JsInterop

2018-02-15 Thread Vassilis Virvilis
Amazing trick!

Obvious if you think about it - but very difficult to think it initially
(for us mere mortals).

   Vassilis

On Thu, Feb 15, 2018 at 11:53 AM, Thomas Broyer  wrote:

>
>
> On Thursday, February 15, 2018 at 10:21:59 AM UTC+1, Scott Shumway wrote:
>>
>> Greetings
>>
>> I am trying to get a DOMRect from an Element. I can do this with JSNI,
>> but have been unable to make a JsInterop version. Here's what I have:
>>
>> public final class DOMRect extends JavaScriptObject
>> {
>>  // returns DOMRect or null
>>  public static native DOMRect getBoundingClientRect(Element element)
>>  /*-{
>>  return element.getBoundingClientRect && element.getBoundingClientRect();
>>  }-*/;
>>
>>  protected DOMRect()
>>  {
>>  }
>>
>>  public final native double getX()
>>  /*-{
>>  return this.x;
>>  }-*/;
>>
>>  // etc.
>> }
>>
>> I can make a JsType for DOMRect, no problem. The issue I'm having is with
>> getBoundingClientRect(). This function may not exist which is why there is
>> a null check.
>>
>
> You'll want a @JsProperty for the method so you can check whether it's
> null or not; and then either declare it also as a @JsMethod in parallel to
> call it, or have the @JsProperty return a @JsFunction (or then cast to an
> elemental2.dom.Element).
> And you can hide the details the same way you did with JSNI, with a
> @JsOverlay:
>
> @JsType(isNative=true, namespace=JsPackage.GLOBAL, name="Element")
> class Element {
>   @JsProperty(name="getBoundingClientRect") private native Object
> getGetBoundingClientRect();
>   @JsMethod(name="getBoundingClientRect") private native DOMRect
> callGetBoundingClientRect();
>
>
>   @JsOverlay
>   public DOMRect getBoundingClientRect() {
> return getGetBoundingClientRect() == null ? null :
> callGetBoundingClientRect();
>   }
> }
>
> or
>
> @JsType(isNative=true, namespace=JsPackage.GLOBAL, name="Element")
> class Element {
>   @JsProperty(name="getBoundingClientRect") public native
> GetBoundingClientRect getBoundingClientRect();
>
>
>   @JsFunction
>   interface GetBoundingClientRect {
> public DOMRect invoke();
>   }
> }
>
>
> If I make an interface for getBoundingClientRect, I'm not allowed to cast
>> Element to implement it.
>>
>
> How so‽
> You cannot use JavaScriptObject#cast(), but you should be able to use a
> standard Java cast.
> You might have to first cast to Object to please javac:
>
> ((HasGetBoundingClientRect) (Object) elt).getBoundingClientRect()
>
>
>
>> I can't extend Element, either. With JSNI, I am allowed to compile
>> Javascript into Javascript, but I can't with JsInterop. It seems like a lot
>> of trouble for 1 line of Javascript.
>>
>> How can I do this? Thanks in advance...
>>
>
> getBoundingClientRect is supported in (literally) all browsers, so don't
> bother and just call the method: https://caniuse.com/#
> feat=getboundingclientrect, https://developer.mozilla.org/
> en-US/docs/Web/API/Element/getBoundingClientRect#Browser_compatibility
>
> --
> 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+unsubscr...@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

-- 
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+unsubscr...@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.


Re: Understanding JsInterop

2018-02-15 Thread Thomas Broyer


On Thursday, February 15, 2018 at 10:21:59 AM UTC+1, Scott Shumway wrote:
>
> Greetings
>
> I am trying to get a DOMRect from an Element. I can do this with JSNI, but 
> have been unable to make a JsInterop version. Here's what I have:
>
> public final class DOMRect extends JavaScriptObject
> {
>  // returns DOMRect or null
>  public static native DOMRect getBoundingClientRect(Element element)
>  /*-{
>  return element.getBoundingClientRect && element.getBoundingClientRect();
>  }-*/;
>
>  protected DOMRect()
>  {
>  }
>
>  public final native double getX()
>  /*-{
>  return this.x;
>  }-*/;
>
>  // etc.
> }
>
> I can make a JsType for DOMRect, no problem. The issue I'm having is with 
> getBoundingClientRect(). This function may not exist which is why there is 
> a null check.
>

You'll want a @JsProperty for the method so you can check whether it's null 
or not; and then either declare it also as a @JsMethod in parallel to call 
it, or have the @JsProperty return a @JsFunction (or then cast to an 
elemental2.dom.Element).
And you can hide the details the same way you did with JSNI, with a 
@JsOverlay:

@JsType(isNative=true, namespace=JsPackage.GLOBAL, name="Element")
class Element {
  @JsProperty(name="getBoundingClientRect") private native Object 
getGetBoundingClientRect();
  @JsMethod(name="getBoundingClientRect") private native DOMRect 
callGetBoundingClientRect();


  @JsOverlay
  public DOMRect getBoundingClientRect() {
return getGetBoundingClientRect() == null ? null : 
callGetBoundingClientRect();
  }
}

or

@JsType(isNative=true, namespace=JsPackage.GLOBAL, name="Element")
class Element {
  @JsProperty(name="getBoundingClientRect") public native 
GetBoundingClientRect getBoundingClientRect();


  @JsFunction
  interface GetBoundingClientRect {
public DOMRect invoke();
  }
}


If I make an interface for getBoundingClientRect, I'm not allowed to cast 
> Element to implement it.
>

How so‽
You cannot use JavaScriptObject#cast(), but you should be able to use a 
standard Java cast.
You might have to first cast to Object to please javac:

((HasGetBoundingClientRect) (Object) elt).getBoundingClientRect()

 

> I can't extend Element, either. With JSNI, I am allowed to compile 
> Javascript into Javascript, but I can't with JsInterop. It seems like a lot 
> of trouble for 1 line of Javascript.
>
> How can I do this? Thanks in advance...
>

getBoundingClientRect is supported in (literally) all browsers, so don't 
bother and just call the 
method: https://caniuse.com/#feat=getboundingclientrect, 
https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect#Browser_compatibility

-- 
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+unsubscr...@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.


Understanding JsInterop

2018-02-15 Thread Scott Shumway
Greetings

I am trying to get a DOMRect from an Element. I can do this with JSNI, but 
have been unable to make a JsInterop version. Here's what I have:

public final class DOMRect extends JavaScriptObject
{
 // returns DOMRect or null
 public static native DOMRect getBoundingClientRect(Element element)
 /*-{
 return element.getBoundingClientRect && element.getBoundingClientRect();
 }-*/;

 protected DOMRect()
 {
 }

 public final native double getX()
 /*-{
 return this.x;
 }-*/;

 // etc.
}

I can make a JsType for DOMRect, no problem. The issue I'm having is with 
getBoundingClientRect(). This function may not exist which is why there is 
a null check. If I make an interface for getBoundingClientRect, I'm not 
allowed to cast Element to implement it. I can't extend Element, either. 
With JSNI, I am allowed to compile Javascript into Javascript, but I can't 
with JsInterop. It seems like a lot of trouble for 1 line of Javascript.

How can I do this? Thanks in advance...

-- 
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+unsubscr...@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.


Re: Trouble understanding JsInterop

2017-04-12 Thread Thomas Broyer


On Wednesday, April 12, 2017 at 9:01:37 AM UTC+2, DavidN wrote:
>
> There is one thing people keep on repeating:
> You can only invoke the exported class/method when the gwt app is loaded.
>

Just like with any asynchronously loading script.
For example, the Google Analytics snippet 
 
sets up window.ga() so you can call it before the script is loaded, queuing 
the calls, and when the script loads it'll (probably) replace window.ga() 
with its own and processing the queued calls.
Shadow AMP works the same (though even 
simpler): https://www.ampproject.org/fr/docs/guides/pwa-amp/amp-in-pwa
 

> Is there a GWT supported default way that would allow this ?
> Otherwise I guess you would need to add a callback mechanism in the 
> EntryPoint (Using JsInterop)
>

You cannot do the same as GA or Shadow AMP by simply exporting some class, 
but this can (probably) be done using a native JsType to read and re-define 
the global variable from your onModuleLoad.
Or you could simply check whether a global variable/function with a 
specific name is defined and then call it from your onModuleLoad (contrary 
to an approach like Shadow AMP, only one such callback could be defined 
then).

-- 
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+unsubscr...@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.


Re: Trouble understanding JsInterop

2017-04-12 Thread Philipp
The JsInterop part worked now - in the end it was the missing 
-generateJsInteropExports and my confusion when to use $wnd and when not.

On Tuesday, 11 April 2017 17:30:39 UTC+2, Thomas Broyer wrote:
>
>
>
> On Tuesday, April 11, 2017 at 4:53:24 PM UTC+2, Philipp Gloor wrote:
>>
>> Where do I use $wnd.test.JsOpClass()? It doesn't work within 

Re: Trouble understanding JsInterop

2017-04-12 Thread David
There is one thing people keep on repeating:
You can only invoke the exported class/method when the gwt app is loaded.

Is there a GWT supported default way that would allow this ?
Otherwise I guess you would need to add a callback mechanism in the
EntryPoint (Using JsInterop)



On Tue, 11 Apr 2017 at 17:30, Thomas Broyer  wrote:

>
>
> On Tuesday, April 11, 2017 at 4:53:24 PM UTC+2, Philipp Gloor wrote:
>
> Where do I use $wnd.test.JsOpClass()? It doesn't work within 

Re: Trouble understanding JsInterop

2017-04-11 Thread Thomas Broyer


On Tuesday, April 11, 2017 at 4:53:24 PM UTC+2, Philipp Gloor wrote:
>
> Where do I use $wnd.test.JsOpClass()? It doesn't work within 

Re: Trouble understanding JsInterop

2017-04-11 Thread Vassilis Virvilis
It should work but you also have to make sure that GWT code is loaded.

So after the crash - hit F12 go to console and try to reference
$wnd.test.JsOpClass
or
put a console print inside onModuleLoad to see when GWT code is loaded:
before or after the crash

  Vassilis

On Tue, Apr 11, 2017 at 5:52 PM, Philipp Gloor 
wrote:

> Where do I use $wnd.test.JsOpClass()? It doesn't work within 

Re: Trouble understanding JsInterop

2017-04-11 Thread Philipp Gloor
Where do I use $wnd.test.JsOpClass()? It doesn't work within 

Re: Trouble understanding JsInterop

2017-04-11 Thread Vassilis Virvilis
Hi,

1. With jsinterop you won't need any JSNI normally.
2. If you have older JSNI code that calls your new code (can't really
happen) you can
  a) use new $wnd.test.JsOpClass(); with -generateJsInteropExports as
Thomas suggested
  b) use the old syntax found here
http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html and that
would be something like @com.test.workertest.shared.JsOpClass::new()() Note
the ()() double parenthesis.

Do you want JsOpClass to be visible from both js and java?


On Tue, Apr 11, 2017 at 5:29 PM, Philipp Gloor 
wrote:

> Can I access Classes and Methods decorated with JsType/JsMethod from
> anywhere within GWT granted I'm inside a JSNI block? Or is it restricted to
> packages?
>
> I added the -generateJsInteropExports to the run configuration arguments
> but when I try to create a new object JsOpClass() it tells me $wnd.pdf is
> undefined.
>
> On 11 April 2017 at 11:32, Thomas Broyer  wrote:
>
>>
>>
>> On Tuesday, April 11, 2017 at 10:43:06 AM UTC+2, Philipp wrote:
>>>
>>> If I have a java class and I mark it with @JsType I create a contract
>>> between Java and Javascript that I can use this class with it's given Java
>>> name in Javascript - is this correct?
>>>
>>> package com.test.workertest.shared;
>>>
>>>
>>> import com.google.gwt.core.shared.GWT;
>>>
>>>
>>> import jsinterop.annotations.*;
>>>
>>>
>>> @JsType(namespace = "test", name = "JsOpClass")
>>> public class JsOpClass
>>> {
>>>
>>>
>>> @JsMethod
>>> public void printStuff()
>>> {
>>> GWT.log("asdfasdf");
>>> }
>>> }
>>>
>>>
>>> I would like to be able to create now a JsOpClass object in javascript
>>> and call printStuff() on this object but I actually don't understand where
>>> this is meant to be working. If I create for example a web worker which
>>> would create this class it reports that
>>>
>>> com.google.gwt.event.shared.UmbrellaException: Exception caught: (
>>> ReferenceError) : testis not defined
>>>
>>> which makes sense because my worker.js knows nothing about GWT (would
>>> this be possible?)
>>>
>>> And even if I try it in the GWT HTML file it doesn't seem to know about
>>> this class and I get a test is not defined error.
>>>
>>> How do I actually call exposed classes/methods and from where is it
>>> possible?
>>>
>>
>> First, you have to pass -generateJsInteropExports to GWT (compiler,
>> codeserver, devmode), to actually export the JsType to JavaScript.
>> Then, from the context the GWT app (*.nocache.js) was loaded in, you
>> should be able to do '(new test.JsOpClass()).printStuff()', *after* your
>> GWT app has been loaded/started (once onModuleLoad has been called)
>>
>>
>>> Is it only a JSNI substitute
>>>
>>
>> Yes.
>>
>>
>>> (but even then I was not able to call it from a JSNI method).
>>>
>>
>> var o = new $wnd.test.JsOpClass();
>> o.printStuff();
>>
>> …but maybe all you miss is the -generateJsInteropExports?
>>
>> --
>> 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/to
>> pic/google-web-toolkit/wpcpNJka5qo/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> google-web-toolkit+unsubscr...@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.
>>
>
> --
> 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+unsubscr...@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

-- 
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+unsubscr...@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.


Re: Trouble understanding JsInterop

2017-04-11 Thread Philipp Gloor
NB: I changed the namespace from test to pdf -> that's why it is now
$wnd.pdf is undefined.

On 11 April 2017 at 16:29, Philipp Gloor  wrote:

> Can I access Classes and Methods decorated with JsType/JsMethod from
> anywhere within GWT granted I'm inside a JSNI block? Or is it restricted to
> packages?
>
> I added the -generateJsInteropExports to the run configuration arguments
> but when I try to create a new object JsOpClass() it tells me $wnd.pdf is
> undefined.
>
> On 11 April 2017 at 11:32, Thomas Broyer  wrote:
>
>>
>>
>> On Tuesday, April 11, 2017 at 10:43:06 AM UTC+2, Philipp wrote:
>>>
>>> If I have a java class and I mark it with @JsType I create a contract
>>> between Java and Javascript that I can use this class with it's given Java
>>> name in Javascript - is this correct?
>>>
>>> package com.test.workertest.shared;
>>>
>>>
>>> import com.google.gwt.core.shared.GWT;
>>>
>>>
>>> import jsinterop.annotations.*;
>>>
>>>
>>> @JsType(namespace = "test", name = "JsOpClass")
>>> public class JsOpClass
>>> {
>>>
>>>
>>> @JsMethod
>>> public void printStuff()
>>> {
>>> GWT.log("asdfasdf");
>>> }
>>> }
>>>
>>>
>>> I would like to be able to create now a JsOpClass object in javascript
>>> and call printStuff() on this object but I actually don't understand where
>>> this is meant to be working. If I create for example a web worker which
>>> would create this class it reports that
>>>
>>> com.google.gwt.event.shared.UmbrellaException: Exception caught: (
>>> ReferenceError) : testis not defined
>>>
>>> which makes sense because my worker.js knows nothing about GWT (would
>>> this be possible?)
>>>
>>> And even if I try it in the GWT HTML file it doesn't seem to know about
>>> this class and I get a test is not defined error.
>>>
>>> How do I actually call exposed classes/methods and from where is it
>>> possible?
>>>
>>
>> First, you have to pass -generateJsInteropExports to GWT (compiler,
>> codeserver, devmode), to actually export the JsType to JavaScript.
>> Then, from the context the GWT app (*.nocache.js) was loaded in, you
>> should be able to do '(new test.JsOpClass()).printStuff()', *after* your
>> GWT app has been loaded/started (once onModuleLoad has been called)
>>
>>
>>> Is it only a JSNI substitute
>>>
>>
>> Yes.
>>
>>
>>> (but even then I was not able to call it from a JSNI method).
>>>
>>
>> var o = new $wnd.test.JsOpClass();
>> o.printStuff();
>>
>> …but maybe all you miss is the -generateJsInteropExports?
>>
>> --
>> 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/to
>> pic/google-web-toolkit/wpcpNJka5qo/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> google-web-toolkit+unsubscr...@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.
>>
>
>

-- 
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+unsubscr...@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.


Re: Trouble understanding JsInterop

2017-04-11 Thread Philipp Gloor
Can I access Classes and Methods decorated with JsType/JsMethod from
anywhere within GWT granted I'm inside a JSNI block? Or is it restricted to
packages?

I added the -generateJsInteropExports to the run configuration arguments
but when I try to create a new object JsOpClass() it tells me $wnd.pdf is
undefined.

On 11 April 2017 at 11:32, Thomas Broyer  wrote:

>
>
> On Tuesday, April 11, 2017 at 10:43:06 AM UTC+2, Philipp wrote:
>>
>> If I have a java class and I mark it with @JsType I create a contract
>> between Java and Javascript that I can use this class with it's given Java
>> name in Javascript - is this correct?
>>
>> package com.test.workertest.shared;
>>
>>
>> import com.google.gwt.core.shared.GWT;
>>
>>
>> import jsinterop.annotations.*;
>>
>>
>> @JsType(namespace = "test", name = "JsOpClass")
>> public class JsOpClass
>> {
>>
>>
>> @JsMethod
>> public void printStuff()
>> {
>> GWT.log("asdfasdf");
>> }
>> }
>>
>>
>> I would like to be able to create now a JsOpClass object in javascript
>> and call printStuff() on this object but I actually don't understand where
>> this is meant to be working. If I create for example a web worker which
>> would create this class it reports that
>>
>> com.google.gwt.event.shared.UmbrellaException: Exception caught: (
>> ReferenceError) : testis not defined
>>
>> which makes sense because my worker.js knows nothing about GWT (would
>> this be possible?)
>>
>> And even if I try it in the GWT HTML file it doesn't seem to know about
>> this class and I get a test is not defined error.
>>
>> How do I actually call exposed classes/methods and from where is it
>> possible?
>>
>
> First, you have to pass -generateJsInteropExports to GWT (compiler,
> codeserver, devmode), to actually export the JsType to JavaScript.
> Then, from the context the GWT app (*.nocache.js) was loaded in, you
> should be able to do '(new test.JsOpClass()).printStuff()', *after* your
> GWT app has been loaded/started (once onModuleLoad has been called)
>
>
>> Is it only a JSNI substitute
>>
>
> Yes.
>
>
>> (but even then I was not able to call it from a JSNI method).
>>
>
> var o = new $wnd.test.JsOpClass();
> o.printStuff();
>
> …but maybe all you miss is the -generateJsInteropExports?
>
> --
> 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/wpcpNJka5qo/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> google-web-toolkit+unsubscr...@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.
>

-- 
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+unsubscr...@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.


Re: Trouble understanding JsInterop

2017-04-11 Thread Thomas Broyer


On Tuesday, April 11, 2017 at 10:43:06 AM UTC+2, Philipp wrote:
>
> If I have a java class and I mark it with @JsType I create a contract 
> between Java and Javascript that I can use this class with it's given Java 
> name in Javascript - is this correct?
>
> package com.test.workertest.shared;
>
>
> import com.google.gwt.core.shared.GWT;
>
>
> import jsinterop.annotations.*;
>
>
> @JsType(namespace = "test", name = "JsOpClass")
> public class JsOpClass
> {
>
>
> @JsMethod
> public void printStuff()
> {
> GWT.log("asdfasdf");
> }
> }
>
>
> I would like to be able to create now a JsOpClass object in javascript and 
> call printStuff() on this object but I actually don't understand where this 
> is meant to be working. If I create for example a web worker which would 
> create this class it reports that 
>
> com.google.gwt.event.shared.UmbrellaException: Exception caught: (
> ReferenceError) : testis not defined
>
> which makes sense because my worker.js knows nothing about GWT (would this 
> be possible?)
>
> And even if I try it in the GWT HTML file it doesn't seem to know about 
> this class and I get a test is not defined error.
>
> How do I actually call exposed classes/methods and from where is it 
> possible?
>

First, you have to pass -generateJsInteropExports to GWT (compiler, 
codeserver, devmode), to actually export the JsType to JavaScript.
Then, from the context the GWT app (*.nocache.js) was loaded in, you should 
be able to do '(new test.JsOpClass()).printStuff()', *after* your GWT app 
has been loaded/started (once onModuleLoad has been called)
 

> Is it only a JSNI substitute
>

Yes.
 

> (but even then I was not able to call it from a JSNI method).
>

var o = new $wnd.test.JsOpClass();
o.printStuff();

…but maybe all you miss is the -generateJsInteropExports?

-- 
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+unsubscr...@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.


Trouble understanding JsInterop

2017-04-11 Thread Philipp
If I have a java class and I mark it with @JsType I create a contract 
between Java and Javascript that I can use this class with it's given Java 
name in Javascript - is this correct?

package com.test.workertest.shared;


import com.google.gwt.core.shared.GWT;


import jsinterop.annotations.*;


@JsType(namespace = "test", name = "JsOpClass")
public class JsOpClass
{


@JsMethod
public void printStuff()
{
GWT.log("asdfasdf");
}
}


I would like to be able to create now a JsOpClass object in javascript and 
call printStuff() on this object but I actually don't understand where this 
is meant to be working. If I create for example a web worker which would 
create this class it reports that 

com.google.gwt.event.shared.UmbrellaException: Exception caught: (
ReferenceError) : testis not defined

which makes sense because my worker.js knows nothing about GWT (would this 
be possible?)

And even if I try it in the GWT HTML file it doesn't seem to know about 
this class and I get a test is not defined error.

How do I actually call exposed classes/methods and from where is it 
possible? Is it only a JSNI substitute (but even then I was not able to 
call it from a JSNI method).

-- 
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+unsubscr...@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.