Java 如何从ValueListBox值中删除空值

Java 如何从ValueListBox值中删除空值,java,google-app-engine,gwt,Java,Google App Engine,Gwt,我是GWT的新手。我正在编写一个简单的GWT程序,其中需要使用一个组合框,我使用了ValueListBox的一个实例。在这个组合中,我需要列出1到12之间代表一年中月份的数字。但是组合框在末尾追加null值。有人能帮我删除这个null值吗 final ValueListBox<Integer> monthCombo = new ValueListBox<Integer>(new Renderer<Integer>() { @O

我是GWT的新手。我正在编写一个简单的GWT程序,其中需要使用一个组合框,我使用了
ValueListBox
的一个实例。在这个组合中,我需要列出1到12之间代表一年中月份的数字。但是组合框在末尾追加
null
值。有人能帮我删除这个
null
值吗

    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;
    }
final ValueListBox monthCombo=new ValueListBox(new Renderer()){
@凌驾
公共字符串呈现(整数对象){
返回字符串.valueOf(对象);
}
@凌驾
公共void呈现(整数对象,可追加可追加)引发IOException{
if(对象!=null){
字符串值=渲染(对象);
append.append(值);
}
}
});
setAcceptableValues(getMonthList());
monthCombo.setValue(1);
私有列表getMonthList(){
列表=新的ArrayList();

对于(int i=1;i在
setAcceptableValues
之前调用
setValue

原因是调用
setAcceptableValues
时,值为
null
,并且
ValueListBox
会自动将任何值(通常传递到
setValue
)添加到可接受值列表中(因此,该值实际上已设置,用户可以选择,如果她选择了另一个值并希望返回到原始值,则可以重新选择)。首先使用可接受值列表中的值调用
setValue
,可以消除此副作用

请参见以下引述:

注意setAcceptableValues会自动添加当前值 (由getValue返回,默认为null)添加到列表(和setValue 如果出现以下情况,也会自动将该值添加到可接受值列表中 (需要)

因此,尝试将调用setValue和setAcceptableValues的顺序颠倒如下:

monthCombo.setValue(1);
monthCombo.setAcceptableValues(getMonthList());

我刚才引用了你对之前一个类似问题的回答,哈哈:)我尝试了这个,但它不起作用。我仍然看到null…它感觉像一个bug,而不是一个功能。我正在运行2.5-rc1@ThomasBroyer:如果我们事先不知道任何可接受的值可能是什么,该怎么办?如果我们只想要可接受的值,而不需要null或空字符串,该如何使用?更新:我看到
setAcceptableValues(Collections.emptyList());
建议用于此操作,但不起作用