How to render a list(ul li) by gwt widget ?

6,126 views
Skip to first unread message

Jason

unread,
Jan 15, 2009, 3:57:55 PM1/15/09
to Google Web Toolkit
I want to use gwt widgets to render a list, the result should look
like this:

<ul>
<li><a href="***">About</a></li>
<li><a href="***">About</a></li>
<li><a href="***">About</a></li>
</ul>

I'm not sure which widget will meet my need. The HTML widget seams can
get the result, but it is not the perfect solution. could someone help
me ?

Jason Essington

unread,
Jan 15, 2009, 4:35:15 PM1/15/09
to Google-We...@googlegroups.com
There is a feature request for a UL and LI widget, however they are
not yet included ... however, they aren't that difficult to create,
I've had to do it for a couple of projects.

You can use FlowPanel as your guide, and create similar widgets using
the ul and li element. you could add additional methods as need be,
but the simple add(widget w) method is minimally sufficient.

-jason

Jason

unread,
Jan 15, 2009, 5:40:50 PM1/15/09
to Google Web Toolkit
Hi, Jason, Thank you for your reply!

I'v tryied many ways, but failed. I'v get the following result:
<ul>
<li>
<div>
<a href="">aa</a>
</div>
</li>
</ul>
It seems work in IE, but failed in Firefox.
So, could you do me a favour to send me your widget code? I'll so
appriciate about it!
> > me ?- 隐藏被引用文字 -
>
> - 显示引用的文字 -

alex.d

unread,
Jan 16, 2009, 2:24:50 AM1/16/09
to Google Web Toolkit
I would suppose that since most of the google widgets are <div> or
include div elemente it is easier just to take a HTMLPanel and fill it
with right tags and info.

luisfpg

unread,
Jan 16, 2009, 6:31:30 AM1/16/09
to Google Web Toolkit
Create a class like this:

public class ULPanel extends ComplexPanel {

private UListElement list;

public BulletPanel() {
list = Document.get().createULElement();
setElement(list);
}

@Override
public void add(Widget child) {
Element li = Document.get().createLIElement().cast();
list.appendChild(li);
super.add(child, li);
}
}

Jason

unread,
Jan 16, 2009, 12:27:07 PM1/16/09
to Google Web Toolkit
Thanks for all your reply.

I'v find a perfect solution, here they are, hope this would help other
peoples:

public class OrderedList extends ComplexPanel {
public OrderedList() {
setElement(DOM.createElement("OL"));
}

public void add(Widget w) {
super.add(w, getElement());
}

public void insert(Widget w, int beforeIndex) {
super.insert(w, getElement(), beforeIndex, true);
}

}

public class ListItem extends ComplexPanel implements HasText {
public ListItem() {
setElement(DOM.createElement("LI"));
}

public void add(Widget w) {
super.add(w, getElement());
}

public void insert(Widget w, int beforeIndex) {
super.insert(w, getElement(), beforeIndex, true);
}

public String getText() {
return DOM.getInnerText(getElement());
}

public void setText(String text) {
DOM.setInnerText(getElement(), (text == null) ? "" : text);
Reply all
Reply to author
Forward
0 new messages