问题
i really doesnt understand for what the class AttachEvent or the addAttachHandler is. For what is this usefull? could somebody post an example for that? Thx a lot.
回答1:
The AttachEvent informs you when a Widget is either attached or detached from the actual page. If something isn't attached, there is no way its elements can be visible or interacted with, so it can be beneficial to know when it isn't available for interaction.
The main thing that GWT itself uses this knowledge for is for wiring up event handling code. If a widget isn't attached to the dom, it can't be interacted with, so all handlers are temporarily detached from the dom. This is done as part of GWT's method for dealing with memory leaks (see http://code.google.com/p/google-web-toolkit/wiki/DomEventsAndMemoryLeaks and http://code.google.com/p/google-web-toolkit/wiki/UnderstandingMemoryLeaks for more details). You generally shouldn't need to worry about this detail, unless you are wiring in your own dom listeners, or building container for other widgets. One of the primary duties of a container is to inform its children when it has been attached or detached.
来源:https://stackoverflow.com/questions/10131920/for-what-is-the-attachevent