I am new to GWT. I am writing a simple GWT program where I need to use a combo box for which I used an instance of ValueListBox
. In that combo, I need to list out the numbers from 1 to 12 representing the months of a year. But the combo appends null
value at the end. Can anyone please help me how to remove that null
value ?
final ValueListBox<Integer> monthCombo = new ValueListBox<Integer>(new Renderer<Integer>() {
@Override
public String render(Integer object) {
return String.valueOf(object);
}
@Override
public void render(Integer object, Appendable appendable) throws IOException {
if (object != null) {
String value = render(object);
appendable.append(value);
}
}
});
monthCombo.setAcceptableValues(getMonthList());
monthCombo.setValue(1);
private List<Integer> getMonthList() {
List<Integer> list = new ArrayList<Integer>();
for (int i = 1; i <= 12; i++) {
list.add(i);
}
return list;
}
Call setValue
before setAcceptableValues
.
The reason is that the value is null
when you call setAcceptableValues
, and ValueListBox
automatically adds any value (generally passed to setValue
) to the list of acceptable values (so that the value is actually set, and can be selected by the user, and re-selected if she selected another value and wants to go back to the original one). Calling setValue
first with a value that will be in the list of acceptable values negates this side-effect.
See http://code.google.com/p/google-web-toolkit/issues/detail?id=5477
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With