Hey Gert,

Thanks for the reply! I realised my problem with appending an
Element..I was trying to append it to a TextNode which I think isn't
allowed. So I've sorted that, I append to the text node's Parent now.

On adding Widgets to a certain point in the DOM..this seems to work
for me:

I create the Widget, and add it to RootPanel. Then, I get its element
and append that to the appropriate Node. This moves the widget to the
correct place in the DOM, and at first glance I get the behaviours I
would expect (e.g. the Widget's clicklisteners work etc.).

Is it safe to do things this way or are there other 'gotchas' I should
be aware of, when manipulating the position of a Widget's element in
the page?

Thanks again for all your help!

On Jun 11, 10:48 am, gscholt <gsch...@gmail.com> wrote:
> Hi,
>
> Widgets are added to widgets, elements are added to elements.
> If you want to put a widget into the dom, I'd use a RootPanel, since
> it will take care of the unloading that is needed:
>
> p = RootPanel.get(currentElement.getId());
> p.add(someWidget);
>
> if currentElement doesn't have an Id, you could use
>   currentElement.setId(DOM.createUniqueId());
> to set one.
>
> Note that these are Elements, not Nodes; not every node is an element,
> and not every node is allowed to have children (which is probably why
> the appendChild fails, but without more information then "an
> exception" it is hard to be sure).
>
> Gert
>
> On Jun 10, 11:51 pm, peterk <peter.ke...@gmail.com> wrote:
>
>
>
> > Hey Jason,
>
> > Thanks for your reply!
>
> > I'm afraid I'm still running into problems here. First, even just
> > trying to insert an element. I have this code:
>
> > SpanElement test_element = Document.get().createSpanElement();
> > test_element.setInnerText("Hello there");
> > currentNode.appendChild(test_element);
>
> > currentNode is of type Node. This compiles OK, but at run time I get
> > an exception on the appendChild call.
>
> > How can I add or append an element to a node like this?
>
> > Secondly..I can't seem to find any wrap method in the Widget class?
>
> > Any further insight would be greatly appreciated..thanks so much!
>
> > On Jun 10, 8:41 pm, Jason Essington <jason.essing...@gmail.com> wrote:
>
> > > Probably the safest thing to do would be to insert an element, then  
> > > use the widget's .wrap() method to "promote" that element to a widget.
>
> > > there are other ways, but they are prone to leaking memory.
>
> > > -jason
>
> > > On Jun 10, 2009, at 1:36 PM, peterk wrote:
>
> > > > Hey all,
>
> > > > I'm walking the DOM tree and would like to append a Widget to certain
> > > > nodes where certain conditions are met, but I'm not having much
> > > > success.
>
> > > > appendChild expects a Node as its parameter, so I can't just append a
> > > > type of Widget. It will accept Widget.getElement() as a parameter, but
> > > > this leads to runtime errors.
>
> > > > Is it possible to mix Widgets with the DOM like this or is the only
> > > > way to add Widgets to a page via the RootPanel.get() ..? If so is
> > > > there a way to add Widgets to the page based on a desired position in
> > > > the DOM?
>
> > > > I'd like to use a custom widget I've made, having everything wrapped
> > > > neatly in a class, and not have to revert to lower level stuff..
>
> > > > Thanks for any help :)- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
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-Toolkit@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