Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove null value from ValueListBox values

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;
    }

enter image description here

like image 641
Manoj Shrestha Avatar asked Jun 24 '12 10:06

Manoj Shrestha


1 Answers

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

like image 62
Thomas Broyer Avatar answered Oct 15 '22 10:10

Thomas Broyer