First of all, a listbox with 8000 typically is unlikely to be user
friendly, perhaps you should be using a SuggestBox instead?
However, if you really do want a listbox, you're on the right track in
that using HTML is the only way to get reasonable performance with a
large number of elements in IE.
The reason your second example is still slow is because of all the
string concatenation overhead - you should be using a stringbuilder
here.
I put together a quick test using StringBuilder:
StringBuilder htmlSelect = new StringBuilder();
htmlSelect.append("<select>");
for (int i = 0; i < 8000; i++) {
htmlSelect.append("<option>").append(i).append("</option>");
}
htmlSelect.append("</select>");
HTML html = new HTML(htmlSelect.toString());
RootPanel.get().add(html);
On my eee netbook running IE6:
- your first example, using ListBox directly takes 70 seconds for the
8000 elements
- your second example, using HTML but with +=, takes 24 seconds for
8000 elements
- my example, using HTML with StringBuilder, takes 0.6 seconds
Unfortunately, by using HTML instead of ListBox, you lose all the nice
methods available in ListBox.
I don't think ListBox.wrap() will work if you are creating the listbox
this way, but if you use a HtmlPanel and get the native Select
element, I believe you can do something like this:
public class MyListBox extends Composite {
private final SelectElement _select;
public MyListBox() {
String id = HTMLPanel.createUniqueId();
StringBuilder htmlSelect = new StringBuilder();
htmlSelect.append("<select id='").append(id).append("'>");
for (int i = 0; i < 8000; i++) {
htmlSelect.append("<option>").append(i).append("</option>");
}
htmlSelect.append("</select>");
HTMLPanel htmlPanel = new HTMLPanel(htmlSelect.toString());
_select = SelectElement.as(htmlPanel.getElementById(id));
initWidget(htmlPanel);
}
public String getValue(int index) {
return _select.getOptions().getItem(index).getValue();
}
public int getSelectedIndex() {
return _select.getSelectedIndex();
}
//etc...
}
Anyone know of any downfalls to this approach?
On Jul 30, 8:59 am, Enea <[email protected]> wrote:
> Hi.
>
> I'm populating ListBoxwith 8000 items.
>
> ListBoxlb=newListBox();
> for(int i=0;i<8000;i++)
> lb1.addItem(""+i);
>
> RootPanel.get().add(lb1);
>
> In my real project I have to add items from a big list of cities, but
> anyway.
> That takes 5 seconds on my developer machine, in hosted mode.
> In IE is a wasting 15-20 seconds :(
>
> Trying making some test, it result that with Safari is working very
> good...slower than a second.
> I have to develop for IE...unfortunately.
>
> So, i've tried that:
>
> String HtmlSelect="<select>";
> for(int i=0;i<8000;i++)
> HtmlSelect+="<option>"+i+"</option>";
>
> HtmlSelect+="</select>";
> HTML html=new HTML(HtmlSelect);
> RootPanel.get().add(html);
>
> But that give me slower result...
>
> this is the same issue
> ofhttp://code.google.com/p/google-web-toolkit/issues/detail?id=49
>
> any faster solution?
>
> Thanks in advance!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---