No, I'm not going to write your code for you.

You need to first attach the elements to the actual DOM first just like the
exception says.

Any number of ways to do that:

<ul id="towrap"></ul>

UListElement ul = (UListElement) DOM.getElementById("towrap")

or

UListElement ul = Document.get().createULElement();
Document.get().getBody().appendChild(ul);

etc, etc

On Thu, Apr 16, 2009 at 1:01 AM, dayre <david.c.a...@gmail.com> wrote:

>
> Vitali, this looks fairly straight forward... but now i'm having
> trouble wrapping this with a Composite so i can create my "clickable
> list" wiget.    The issue is the HTML.wrap() which gives me an
> exception due to the element not being attached to the DOM ?... i'm
> missing something, but it's not apparent to me what it is and i'm
> having problems finding any solid examples in this list.
>
> Would you be so kind as to provide a version of your code wrapped in a
> class that extends Composite ?
>
> On Apr 15, 9:15 am, Vitali Lovich <vlov...@gmail.com> wrote:
> > public LIElement appendLI(UListElement ul, String text)
> > {
> >     LIElement li = Document.get().createLIElement();
> >     li.setText(text);
> >     ul.appendChild(li);
> >     return li;
> >
> > }
> >
> > final UListElement ul = Document.get().createULElement();
> > final LIElement li1 = appendLI(ul, "my text 1");
> > final LIElement li2 = appendLI(ul, "my text 2");
> >
> > HTML myList = HTML.wrap(ul);
> >
> > myList.addClickHandler(new ClickHandler() {
> >   public void onClick(ClickEvent event) {
> >        Element source = event.getRelativeElement();
> >        if (source != null) {
> >             Window.alert(source.getInnerText() + " clicked");
> >        } else {
> >             Window.alert("unexpected - event is relative to window");
> >        }
> >   }
> >
> > });
> >
> > Problem solved using plain GWT & you won't create memory leaks.
> >
> > On Wed, Apr 15, 2009 at 9:25 AM, dayre <david.c.a...@gmail.com> wrote:
> >
> > > HI Vitali,
> >
> > > Thank you for taking the time to respond.  I very much appreciate it.
> >
> > > The reason i'm not using existing GWT widgets, which my example
> > > doesn't show, is because i'm trying to attach an onclick() event to
> > > ordered list items (<li>text</li>).   There doesn't seem to be a
> > > widget which easily allows for this.   Someone else in this group had
> > > suggested they do what i was trying to do.   I'm trying to port an
> > > existing interface which i did in jquery() to GWT... one of the key
> > > components uses plain list items which i attach listeners to.
> >
> > > What you explain makes sense and your option #2 for using the jsni
> > > name of the java function seems the easiest.   I will also dig into
> > > the JSNI much deeper to fully understand how it works... i was trying
> > > to avoid that ;)
> >
> > > Again thank you !
> >
>

--~--~---------~--~----~------------~-------~--~----~
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