0

我尝试使用组合框和重置按钮构建一个简单表单。我想丢弃我可以重置组合框。我做错了什么?未注释的 combobox.select 是一种解决方法。

按照简单的例子:

public class VaadinprojectApplication extends Application {

@Override
public void init() {
    final Window mainWindow = new Window("Simpleform");

    final List<String> aListWithStrings = new ArrayList<String>();
    aListWithStrings.add("Somthing");
    final BeanItemContainer<String> objects = new BeanItemContainer<String>(String.class, aListWithStrings);
    final ComboBox comboBox = new ComboBox("Importers", objects);

    // reset button
    final Button resetButton = new Button("Reset", new Button.ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            // comboBox.select(comboBox.getNullSelectionItemId());
            comboBox.discard();
            System.out.println("reset");
        }
    });
    final FormLayout form = new FormLayout();
    form.addComponent(comboBox);
    form.addComponent(resetButton);
    form.setSizeUndefined();

    mainWindow.addComponent(form);
    setMainWindow(mainWindow);
}
}
4

2 回答 2

0

final ComboBox comboBox = new ComboBox("Importers", objects);

The Line above doesn't set the datasource properly. discard()checks if the datasource != null. But in the case of the code example the datasource is null and so nothing happends. Why? I don't know yet.

于 2013-02-11T14:42:50.857 回答
0

为了在组合框中不选择任何内容,请使用它而不是discard()

comboBox.setValue(null);
于 2013-02-08T21:12:48.973 回答