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.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to