【问题标题】:Vaadin ComboBox setValue not workingVaadin ComboBox setValue 不起作用
【发布时间】:2017-03-16 05:26:10
【问题描述】:

设置值后,我在 vaadin 组合框中遇到问题。这是我的代码

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());

【问题讨论】:

  • 究竟是什么不起作用?是否存在错误或意外行为?
  • 猜测:您的分销商没有提供适当的平等方式,因此组合框使用对象标识,因此客户分销商是另一个对象,不会在容器中找到因此未被选中。

标签: combobox vaadin


【解决方案1】:

你可以检查 distributorService.find(null).contains(this.entity.getCustomer().getDistributor()) 是否因为 Vaadin 使用了 Bean 的 equals 函数(在这种情况下是 Distributor)。

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

如果上述任何语句返回 true,则选择应该有效。 也许客户端不更新其内容?试试getUI().access( () -&gt; getUI().push());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多