how to get the list box value in gwt

3,662 views
Skip to first unread message

rajasekhar

unread,
Jan 7, 2009, 10:28:02 AM1/7/09
to Google Web Toolkit
Hi All,

How to get the selected list box value.I have to display
field is username and value is email. when username is selected I need
to get value as email id . Please help me on this regard.




Regards,
Rajasekhar

olivier FRESSE

unread,
Jan 8, 2009, 5:50:19 AM1/8/09
to Google-We...@googlegroups.com
When you fill your listbox, use the following method :

addItem(java.lang.String item, java.lang.String value)



getSelectedIndex() returns the selected index. Or -1 if nothing is selected...

then you have a couple of methods to retrieve the otem text or the value text.

getItemText(int index)

getValue(int index)

regards.

2009/1/7 rajasekhar <raj...@gmail.com>

Jeff

unread,
Jan 22, 2009, 9:44:50 AM1/22/09
to Google Web Toolkit
On Jan 7, 10:28 am, rajasekhar <raja...@gmail.com> wrote:
> How to get the selected list box value.I have to display
> field is username and value is email. when username is selected I need
> to get  value as email id . Please help me on this regard.

For widget w, this snippet would work:

w.getValue(w.getSelectedIndex());

I ended up subclassing ListBox to "CustomListBox" with the following
methods for getting and setting widget value:

public String getWidgetValue() {
try {
return getValue(getSelectedIndex());
} catch (Exception e) {
return new String("");
}
}

public void setWidgetValue(String val) {
if (getItemCount() > 0) {
for (int iter = 0; iter < getItemCount(); iter+
+) {
if (getValue(iter).compareTo(val) ==
0) {
this.setItemSelected(iter,
true);
}
}
}
}

... Those should allow you to easily get and set widget values, so
long as you extend ListBox to include them.

--
Thanks,
Jeff
(je...@freemedsoftware.org)
FreeMED Software Foundation, Inc
http://freemedsoftware.org/
Reply all
Reply to author
Forward
0 new messages