Re: JSNI Issue

2009-08-17 Thread Robert Zaleski

We pass the scope, the this, around with callbacks.  We started doing
this before we tried GWT as it's allot quicker to pass two variables
(scope and cb) instead of making a closure.  Ext.js also uses this.
Then the caller just does

cb.call(scope, extra args);

I've done this a few times in GWT and it works.

If you want an object you can call multiple methods on, I'd use the
Exporter stuff at

http://code.google.com/p/gwt-exporter/downloads/list

It lets you new and call an object multiple times.  It also will
export your static methods for you, and let you pass objects into
them.  So it's nice.  I currently use a mixture of both to integrate
with some legacy code.

On Aug 17, 10:37 am, Thomas Broyer  wrote:
> On 17 août, 16:31, CI-CUBE  wrote:
>
> > My workaround is to use static methods (1 for each Callback) in the
> > base class that redirect the request to virtual members of a static
> > member object. This introduces some overhead but works... anyway is
> > there some advice how to use a true member method in an assignment to
> > a JS callback?
> > > > >        protected native void initializeCBs() /*-{
>
>             var that = this;
>             $wnd.x4ResizeAppCB = function() {
>
> th...@com.egr.x4gpl.apps.saturn.client.application.resizecb()();
>             };
>
> > > > >        }-*/;
>
> It's basically the same as what you described above, without the need
> for Java statics.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---



Re: JSNI Issue

2009-08-17 Thread Thomas Broyer



On 17 août, 16:31, CI-CUBE  wrote:
> My workaround is to use static methods (1 for each Callback) in the
> base class that redirect the request to virtual members of a static
> member object. This introduces some overhead but works... anyway is
> there some advice how to use a true member method in an assignment to
> a JS callback?

> > > >        protected native void initializeCBs() /*-{
var that = this;
            $wnd.x4ResizeAppCB = function() {
 
th...@com.egr.x4gpl.apps.saturn.client.application.resizecb()();
};

> > > >        }-*/;

It's basically the same as what you described above, without the need
for Java statics.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---



Re: JSNI Issue

2009-08-17 Thread CI-CUBE

My workaround is to use static methods (1 for each Callback) in the
base class that redirect the request to virtual members of a static
member object. This introduces some overhead but works... anyway is
there some advice how to use a true member method in an assignment to
a JS callback?

TIA,

   Ekki

GWT 1.7, App Engine 1.2.2, Eclipse 3.5, JRE 1.6.0_13

CI-CUBE.BIZ feat. CubeBrowser.AppSpot.com


On Aug 13, 4:39 pm, CI-CUBE  wrote:
> sorry, but same result
>
> On Aug 13, 4:36 pm, olivier nouguier 
> wrote:
>
> > Hi,
> >  I cannot test from here but could you try to replace (call and function
> > definiotion of course ;) :
>
> >  initializeCBs();
>
> > by:
>
> >  initializeCBs(this);
>
> > HIH
>
> > On Thu, Aug 13, 2009 at 4:30 PM, CI-CUBE  wrote:
>
> > > Hi,
>
> > > I'm assigning a Java method M to a JS Callback. If M is static it
> > > works. If M is non-static I get an error when calling the M via JS.
>
> > > // THE BASE CLASS
>
> > > package com.egr.x4gpl.apps.saturn.client;
>
> > > abstract class Application {
> > >        protected Application(String pUnused) {
> > >                initializeCBs();
> > >        }
>
> > >        protected native void initializeCBs() /*-{
> > >                $wnd.x4ResizeAppCB =
> > > th...@com.egr.x4gpl.apps.saturn.client.application::resizeCB();
> > >                $wnd.x4ResizeAppCB();
> > >        }-*/;
>
> > >        abstract public void resizeCB();
> > > }
>
> > > // THE DERIVED CLASS
>
> > > public class Saturn extends Application implements EntryPoint {
> > >        Saturn() {
> > >                super("Unused");
> > >        }
>
> > >        public native void resizeCB() /*-{
> > >                $wnd.alert("non-static invoke");
> > >        }-*/;
>
> > > // THE ERROR (on calling, not on assingment)
>
> > > [ERROR] Failed to create an instance of
> > > 'com.egr.x4gpl.apps.saturn.client.Saturn' via deferred binding
> > > com.google.gwt.core.client.JavaScriptException: (RangeError): Instance
> > > method 'resizeCB' needed a qualifying instance (did you forget to
> > > prefix the call with 'this.'?)
> > >  number: -2146828279
> > >  description: Instance method 'resizeCB' needed a qualifying instance
> > > (did you forget to prefix the call with 'this.'?)
> > >        at 
> > > com.egr.x4gpl.apps.saturn.client.Application.initializeCBs(Native
> > > Method)
> > >        at com.egr.x4gpl.apps.saturn.client.Application.
> > > (Application.java:5)
> > >        at com.egr.x4gpl.apps.saturn.client.Saturn.(Saturn.java:19)
>
> > > TIA for any kinda support!
>
> > >   Ekki
>
> > --
> > A coward is incapable of exhibiting love; it is the prerogative of the
> > brave.
> > --
> > Mohandas Gandhi
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---



Re: JSNI Issue

2009-08-13 Thread CI-CUBE

sorry, but same result


On Aug 13, 4:36 pm, olivier nouguier 
wrote:
> Hi,
>  I cannot test from here but could you try to replace (call and function
> definiotion of course ;) :
>
>  initializeCBs();
>
> by:
>
>  initializeCBs(this);
>
> HIH
>
>
>
> On Thu, Aug 13, 2009 at 4:30 PM, CI-CUBE  wrote:
>
> > Hi,
>
> > I'm assigning a Java method M to a JS Callback. If M is static it
> > works. If M is non-static I get an error when calling the M via JS.
>
> > // THE BASE CLASS
>
> > package com.egr.x4gpl.apps.saturn.client;
>
> > abstract class Application {
> >        protected Application(String pUnused) {
> >                initializeCBs();
> >        }
>
> >        protected native void initializeCBs() /*-{
> >                $wnd.x4ResizeAppCB =
> > th...@com.egr.x4gpl.apps.saturn.client.application::resizeCB();
> >                $wnd.x4ResizeAppCB();
> >        }-*/;
>
> >        abstract public void resizeCB();
> > }
>
> > // THE DERIVED CLASS
>
> > public class Saturn extends Application implements EntryPoint {
> >        Saturn() {
> >                super("Unused");
> >        }
>
> >        public native void resizeCB() /*-{
> >                $wnd.alert("non-static invoke");
> >        }-*/;
>
> > // THE ERROR (on calling, not on assingment)
>
> > [ERROR] Failed to create an instance of
> > 'com.egr.x4gpl.apps.saturn.client.Saturn' via deferred binding
> > com.google.gwt.core.client.JavaScriptException: (RangeError): Instance
> > method 'resizeCB' needed a qualifying instance (did you forget to
> > prefix the call with 'this.'?)
> >  number: -2146828279
> >  description: Instance method 'resizeCB' needed a qualifying instance
> > (did you forget to prefix the call with 'this.'?)
> >        at com.egr.x4gpl.apps.saturn.client.Application.initializeCBs(Native
> > Method)
> >        at com.egr.x4gpl.apps.saturn.client.Application.
> > (Application.java:5)
> >        at com.egr.x4gpl.apps.saturn.client.Saturn.(Saturn.java:19)
>
> > TIA for any kinda support!
>
> >   Ekki
>
> --
> A coward is incapable of exhibiting love; it is the prerogative of the
> brave.
> --
> Mohandas Gandhi
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---



Re: JSNI Issue

2009-08-13 Thread olivier nouguier
Hi,
 I cannot test from here but could you try to replace (call and function
definiotion of course ;) :

 initializeCBs();

by:

 initializeCBs(this);

HIH

On Thu, Aug 13, 2009 at 4:30 PM, CI-CUBE  wrote:

>
> Hi,
>
> I'm assigning a Java method M to a JS Callback. If M is static it
> works. If M is non-static I get an error when calling the M via JS.
>
> // THE BASE CLASS
>
> package com.egr.x4gpl.apps.saturn.client;
>
> abstract class Application {
>protected Application(String pUnused) {
>initializeCBs();
>}
>
>protected native void initializeCBs() /*-{
>$wnd.x4ResizeAppCB =
> th...@com.egr.x4gpl.apps.saturn.client.application::resizeCB();
>$wnd.x4ResizeAppCB();
>}-*/;
>
>abstract public void resizeCB();
> }
>
> // THE DERIVED CLASS
>
> public class Saturn extends Application implements EntryPoint {
>Saturn() {
>super("Unused");
>}
>
>public native void resizeCB() /*-{
>$wnd.alert("non-static invoke");
>}-*/;
>
> // THE ERROR (on calling, not on assingment)
>
> [ERROR] Failed to create an instance of
> 'com.egr.x4gpl.apps.saturn.client.Saturn' via deferred binding
> com.google.gwt.core.client.JavaScriptException: (RangeError): Instance
> method 'resizeCB' needed a qualifying instance (did you forget to
> prefix the call with 'this.'?)
>  number: -2146828279
>  description: Instance method 'resizeCB' needed a qualifying instance
> (did you forget to prefix the call with 'this.'?)
>at com.egr.x4gpl.apps.saturn.client.Application.initializeCBs(Native
> Method)
>at com.egr.x4gpl.apps.saturn.client.Application.
> (Application.java:5)
>at com.egr.x4gpl.apps.saturn.client.Saturn.(Saturn.java:19)
>
> TIA for any kinda support!
>
>   Ekki
> >
>


-- 
A coward is incapable of exhibiting love; it is the prerogative of the
brave.
--
Mohandas Gandhi

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---



JSNI Issue

2009-08-13 Thread CI-CUBE

Hi,

I'm assigning a Java method M to a JS Callback. If M is static it
works. If M is non-static I get an error when calling the M via JS.

// THE BASE CLASS

package com.egr.x4gpl.apps.saturn.client;

abstract class Application {
protected Application(String pUnused) {
initializeCBs();
}

protected native void initializeCBs() /*-{
$wnd.x4ResizeAppCB =
th...@com.egr.x4gpl.apps.saturn.client.application::resizeCB();
$wnd.x4ResizeAppCB();
}-*/;

abstract public void resizeCB();
}

// THE DERIVED CLASS

public class Saturn extends Application implements EntryPoint {
Saturn() {
super("Unused");
}

public native void resizeCB() /*-{
$wnd.alert("non-static invoke");
}-*/;

// THE ERROR (on calling, not on assingment)

[ERROR] Failed to create an instance of
'com.egr.x4gpl.apps.saturn.client.Saturn' via deferred binding
com.google.gwt.core.client.JavaScriptException: (RangeError): Instance
method 'resizeCB' needed a qualifying instance (did you forget to
prefix the call with 'this.'?)
 number: -2146828279
 description: Instance method 'resizeCB' needed a qualifying instance
(did you forget to prefix the call with 'this.'?)
at com.egr.x4gpl.apps.saturn.client.Application.initializeCBs(Native
Method)
at com.egr.x4gpl.apps.saturn.client.Application.
(Application.java:5)
at com.egr.x4gpl.apps.saturn.client.Saturn.(Saturn.java:19)

TIA for any kinda support!

   Ekki
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---