java - Use ClickHandler with a native Javascript object? -


In Javascript, I am creating a SVG shape and adding a click handler to it like this:

  var rect = document.createElementNS ('http://www.w3.org/2000/svg','rect'); Rect.addEventListener ('Click', myClickHandler, Incorrect);  

This works great, I'm trying to create an overlay restore class in GWT. If possible, I would like to do something like this:

  public class SVGRAct javascript object {public resident Zero AddClickHandler (ClickHandler handler) / * - {addEventListener ('click', handler, false); } - * /; }  

In this way I can pass a 'normal' GWT handler to this class, and can use it as a standalone other GWT UI element. I'm not sure how to do the clickhandler object in the implementation of the original Javascript of the object, though how?

Thanks

Because you pass ClickEvent Requires ClickHandler.onClick and it has a problem getting it from JavaScript (AFAICT) - I will go with a slightly different, more "normal" approach:

Create a simple callback interface:

  public interface callback {void execute (); }  

You can pass it directly and call it like this:

{AddEventListener ('click', function () {callback. @ Path.to.your.package.Clallback :: execute () ();}, Incorrect); } - * /;

Or create an intermediate step:

  Public Zero addClickHandler (callback callback) {_addClickHandler (getCallback (callback)); } Private Original Zero _addClickHandler (JavaScript Object Callback) / * - {addEventListener ('click', callback, wrong); } - * /; // It can be moved to a better location Private Static Javascript Object Mill Callback (Callback Callback) / * - {Return Function () {callback. @ Path.to.your.package.Callback :: execute () (); }; } - * /;  

And, of course, you will use it like this:

  SVGRect svg = getMeSVGRect (); Svg.addClickHandler (new callback () {@Override public void execute () {// some stuff}}); Personally, I like the second solution - when it is more code, I like keeping my original / JSN methods private (unless it is an overlay object or something like this) and the code is more readable and less error prone (There is no need to use the Flickr syntax to call java functions from inside native / jnsani code). 


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -