Java 如何在程序中触发vaadin组合框的ValueChangeListener
如何在程序中触发vaadin组合框的ValueChangeListener。 我有一个包含5个值的组合框,如果我将值设置为其中一个值,在程序中使用,那么我想触发ValueChangeListenerJava 如何在程序中触发vaadin组合框的ValueChangeListener,java,combobox,vaadin,valuechangelistener,Java,Combobox,Vaadin,Valuechangelistener,如何在程序中触发vaadin组合框的ValueChangeListener。 我有一个包含5个值的组合框,如果我将值设置为其中一个值,在程序中使用,那么我想触发ValueChangeListener String statusFilterValue = STATUS_FILTER_DEFAULT; if (statusFilterComboBox.isEmpty()) { statusFilterComboBox.addItem(STATUS_FILTER
String statusFilterValue = STATUS_FILTER_DEFAULT;
if (statusFilterComboBox.isEmpty())
{
statusFilterComboBox.addItem(STATUS_FILTER_DEFAULT);
statusFilterComboBox.setNullSelectionAllowed(false);
statusFilterComboBox.setTextInputAllowed(false);
statusFilterComboBox.addItem(MY_CONFLICT_FILTER);
for (ReferenceStatus item : ReferenceStatus.values())
statusFilterComboBox.addItem(item);
}
else
{
statusFilterValue = (String) statusFilterComboBox.getValue();
}
statusFilterComboBox.setValue(statusFilterValue);
// This is where I am trying to trigger the event
statusFilterComboBox.select(statusFilterValue);
statusFilterComboBox.addValueChangeListener(statusFilterComboBoxListener);
您是否尝试过先添加值更改侦听器,然后设置值,而不是相反的方法?我尝试过,它不起作用,然后请提供一个示例,因为我制作了一个快速示例,它工作得很好。另外,请告诉我们您使用的是什么Vaadin版本。正如@Morfic所说,您必须首先调用
addValueChangeListener(您的Listener)
,然后再调用setValue(newValue)
。如果不起作用,请尝试在setValue
内部调试。可能是组合框检测到您的值未列出或已被选中