I have a project using GWT which integrates with existing HTML. I want
to be able to place widgets into the page by retrieving HTML elements
with specific ID's and inserting the widget as a child.
In 1.5 I just used:
RootPanel.get(id).add(widget);
However I found as many people did once upgrading to 1.6 that this
isn't a good way as nested elements cause problems. So I'm trying to
figure out how this should be done. Simple DOM manipulation gets the
widget in the right place and displaying properly but doesn't setup
any of its event handlers properly.
I have two solutions at the moment, although neither are ideal:
Solution 1:
Add the widget to the root panel and then moves it via DOM
manipulation to be a child of its hook element.
RootPanel.get().add(widget);
widget.getElement().getParentElement().removeChild(widget.getElement
());
DOM.getElementById(id).appendChild(widget.getElement());
Solution 2:
Attach via DOM, fix events by calling onAttach via proxy class to get
around onAttach being protected.
DOM.getElementById(id).appendChild(w.getElement());
WidgetUtils.WidgetOnAttach(w);
WidgetUtils Class:
package com.google.gwt.user.client.ui;
public class WidgetUtils {
public static void WidgetOnAttach(Widget w) {
w.onAttach();
}
}
Both these methods seem to work fine, have tried both by converting
all my old 1.5 RootPanel.get(id).add(widget) calls to both of these
methods under 1.6 and all tests have passed. However, both are
somewhat of a hack and I seeing if there is a better way.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---