Awesome, thanks Thomas! That version does exactly what I need. On Feb 15, 3:22 am, Thomas Broyer <[email protected]> wrote: > On Feb 14, 11:19 pm, Jim Douglas <[email protected]> wrote: > > > I've been playing with some code to register oncut against a GWT > > TextBox. The basic event registration seems to be working ok; I get > > to the event handler function, and the "return false" part seems to be > > working as designed (the cut is blocked). The problem is that I'm > > trying to call back from the event handler into a Java method ... but > > it's never getting there. Am I doing something obviously stupid > > here? The syntax looks right, and I'm not getting any errors. But > > when I run this, I get the two alerts bracketing the attempt to call > > from JavaScript to Java, but that method isn't getting invoked. > > that's a "scope" issue (very common in JavaScript). > > > Here's my test code. I added this to the end of StockWatcher > > onModuleLoad(): > > > registerOnCut(nameField.getElement()); > > > And added these functions: > > > public native void registerOnCut(Element element) > > /*-{ > > element.oncut = function() > > { > > $wnd.alert("about to invoke Java doCut"); > > > $entry([email protected]::doCut()); > > The "this" is no longer your class here, as the function is a > callback. First assign it to a variable outside the function and then > pass a function to $entry(), not a reference to the method. > > Which leads to: > > public native void registerOnCut(Element element) /*-{ > var that = this; > element.oncut = function() { > $wnd.alert("about to invoke Java doCut"); > > $entry(function() { > > [email protected]::doCut() > (); > }); > > $wnd.alert("returned from Java doCut"); > return false; > }; > > }-*/; > > (or you could wrap the whole 'oncut' callback in $entry).
-- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
