I need to make a custom GWT widget from HTML and javascript code. The javascript code should be called on the widget, but the javascript should receive the widget DOM component as a parameter.
Also, the widget’s HTML has to be directly dependent on the arguments, given to the widget’s constructor.
What is the “idiomatic” way of doing this?
It is quite simple. You can start by extending
Widgetclass.To create DOM representation, you need to use
Document.get()(or other old api depends on what you prefer).To call external javascript you will need to use JSNI.
Also you will have to override
onDetachandonAttachmethods, so you can notify external JS when your element is added to dom, and when external JS should perform some cleanup (if needed).Example code: