【问题标题】:Vaadin Combobox does not shows nameField from databaseVaadin Combobox 不显示数据库中的 nameField
【发布时间】:2019-02-11 01:27:22
【问题描述】:

我有一个服务类。当我在组合框中设置项目 alldata() 时,它会显示数据库中的所有嵌入数据。如何设置名称字段?

示例:

私有组合框 groundComboBox = new ComboBox("Ground"); groundComboBox.setItems(groundService.getAllGround());

它显示:

Ground(groundId=Shere-Bangla, groundName=Shere-Bangla 国家体育场, city=Dhaka, country=Bangladesh, longitude=90.8, latitude=45.7, capacity=10000, inaugurationDate=2005-02-05)。

我只想显示唯一的名字;

【问题讨论】:

    标签: vaadin vaadin-flow


    【解决方案1】:

    您需要设置标签生成器来定义每个项目的标签。

    groundComboBox.setItemLabelGenerator(Ground::getName);
    

    groundComboBox.setItemLabelGenerator(ground -> ground.getName());
    

    【讨论】:

    • 除此之外,您应该始终定义ComboBox的类型,在这种情况下它是ComboBox<Ground>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-01
    • 2013-03-21
    • 2016-09-28
    相关资源
    最近更新 更多