Saturday, November 23, 2013

ListBox and default selection

In plain old HTML, I can create a select tag, and specify one option as selected, so that it comes up as the selection by default, or gets selected if the user resets the form.

GWT doesn't appear to offer this capability - I don't see anything like setDefaultSelectedIndex(int index), or addItem(String itemText, boolean defaultSelected).  Is this an oversight, or something that was done deliberately?

The situation I'd like to use it for is a set of enumerated column values from a DB, to be listed in alphabetical order, but where the default value isn't the first.  As it stands now, I'm going to have to keep track of the proper index to select when the form is cleared, as opposed to getting it done once when I initially set up the form.

Hmm, that being said, it seems like there's no reset capability anyway - a ResetButton apparently belongs only in a FormPanel, and there's no reset method in ListBox. I suspect that I'm going to have to extend ListBox to provide a way to set a default selected index AND a reset capability. So, this turned into more of a rant than a question, but I'd still be interested in hearing if there was a specific reason those capabilities were left out, or if my anticipated extensions are a bad idea for some reason I haven't thought of.

You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment