2017-03-16 46 views
0

设置值后,我在vaadin组合框中遇到问题。这里是我的代码Vaadin ComboBox setValue不工作

public class ComponentService implements FieldGroupFieldFactory { 
/** 
    * Create Distributor ComboBox 
    */ 
    public ComboBox createComboBoxDistributor(String caption, boolean required) { 
     ComboBox c = new ComboBox(caption); 
     BeanItemContainer<Distributor> beans = new BeanItemContainer<Distributor>(Distributor.class); 
     beans.addAll(distributorService.find(null)); 
     c.setContainerDataSource(beans); 
     c.setFilteringMode(FilteringMode.CONTAINS); 
     c.setRequired(required); 
     return c; 
    } 
} 

ComboBox comboDistributor = componentService.createComboBoxDistributor("Disributor", false); 
comboDistributor.setValue(this.entity.getCustomer().getDistributor()); 
+1

究竟什么不行?是否有错误或意外行为? –

+0

猜测:您的分销商不提供适当的平等手段,因此组合框使用对象标识,因此客户分销商是另一个对象,因此不会在未选中的容器中找到。 – cfrick

回答

0

为Vaadin使用Bean的等号功能(分销商在这种情况下),您可以检查是否distributorService.find(null).contains(this.entity.getCustomer().getDistributor())

或者,您可以检查beans.getItemIds().contains(this.entity.getCustomer().getDistributor());是否返回true。

如果上述任何一个语句返回true,则选择应该起作用。 也许客户不更新其内容?请尝试getUI().access(() -> getUI().push());