Hi "GWT in Action" has an excellent chapter about "Event Handling". It's an old book, probably 2007 and GWT 1.6 but as far as I can tell from looking at the 2.1.M3 API (*com.google.gwt.user.client.ui.Widget) *alot of this hasn't changed much, if at all
I read somewhere that in 2.0 Listeners became handlers,* *The Chapter has about 20+ pages of great content, hopefully that will help you out. Does any know how much the event handling has changed since 1.6?* * On Tue, Oct 5, 2010 at 7:13 AM, Brian <hibr...@gmail.com> wrote: > What's odd (ie, I don't get this stuff yet) is the HTMLPanel's > onAttach doesn't get called when htmlpanel.add() is called. > > Soo.. instead of wrapping the widget, it seems better to wrap the > HTMLPanel and call onAttach on the panel itself, and add it to > RootPanel.detachOnWindowClose(). > > ie, > > Label myLabel = new Label("Hey now"); > myLabel.addClickHandler(..); > MyPanel p = new MyPanel(""); // subclassed HTMLPanel, onAttach is > public > p.add(myLabel, "foo"); > p.onAttach(); // just does: super.onAttach(); > RootPanel.detachOnChildClose(p); // ensures everyone's onDetach > called > > Just guessing here... > > > On Oct 5, 9:40 am, Brian <hibr...@gmail.com> wrote: > > Thanks. > > > > I still have to call onAttach() on my widget in order for the > > ClickHandler to fire. > > > > HTMLPanel hpanel = new HTMLPanel(""); > > Wrapper w = new Wrapper("Test"); > > w.addClickHandler(...); > > w.onAttach(); > > hpanel.add(w, "foo"); > > > > This does clean up the code a lot -- but I'm still left wondering when/ > > where to call onDetach on the wrapper. I'm guessing I'd need to > > subclass HTMLPanel, handle onDetach, and call it on my wrapper. > > > > On Oct 5, 9:20 am, Thomas Broyer <t.bro...@gmail.com> wrote: > > > > > > > > > > > > > > > > > On Oct 5, 2:30 pm, Brian <hibr...@gmail.com> wrote: > > > > > > Hi, > > > > > > I'm trying to figure out onAttach() onDetatch() onDetachChildren() to > > > > ensure I'm not leaking, but I don't quite get it. Is there a > > > > reference somewhere? Am I best digging through the code to figure > out > > > > the flow? I've read the javadocs, but am having a hard time putting > > > > it together. > > > > > > Got a gwt app, server sends me down a block of html (a table which is > > > > a calendar), gwt client takes the html, and calls setInnerHtml() on a > > > > widget. Perfect. > > > > > > The server's html has a <div id="foo"></div> that I want to take > over, > > > > and shove widgets into. > > > > > Have a look at HTMLPanel then. > > > > > > It'd be nice if I could do: > > > > RootPanel().get("foo").add(...); // but this asserts > > > > > > What I've done instead is create a wrapper which subclasses Widget, > > > > implements HasClickHandlers, and makes onAttach() public. > > > > > > Then I create my wrapped Anchor, get the div in the server's html and > > > > append: > > > > > > Anchor link = new Anchor("click me"); > > > > MyWrapper wrapper = new MyWrapper(link.getElement()); > > > > wrapper.addOnClickHandler(...); > > > > wrapper.onAttach(); // without this, I can't handle the clicks > > > > > > HorizontalPanel hp = new HorizontalPanel(); > > > > hp.add(link); > > > > // add more to hp > > > > > > DivElement serverElement = > > > > Document.get().getElementById("foo").cast(); > > > > serverElement.appendChild(hp.getElement()); > > > > > > --- This all works great. I've got my panel in the div, and the link > > > > works. > > > > > > I'm just wondering if I need to do more, as I don't really 'get' the > > > > attach, detach, detachChildren flow. > > > > > Not detaching your widgets when you remove them from the document (and/ > > > or on window.unload) will lead to memory leaks in some browsers > > > (mainly, or maybe even *only*, IE6/7/8). > > > You'll note that RootPanel, and every widget that has a wrap() static > > > method, will register itself to be "detached on window close", which > > > will detach all its children. > > > > > But really, what you're trying to do is already there, in HTMLPanel. > > -- > You received this message because you are subscribed to the Google Groups > "Google Web Toolkit" group. > To post to this group, send email to google-web-tool...@googlegroups.com. > To unsubscribe from this group, send email to > google-web-toolkit+unsubscr...@googlegroups.com<google-web-toolkit%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/google-web-toolkit?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.