【问题标题】:Bind Boolean Value to a combobox in Vaadin将布尔值绑定到 Vaadin 中的组合框
【发布时间】:2012-08-06 12:49:03
【问题描述】:

我有一个 POJO,它的客户性别值为布尔值。我必须以数据源为客户类型的形式制作一个组合框。 如何使组合框具有将绑定到布尔值的“男性”和“女性”选项。

谢谢。 表格代码:

Form customerForm= new BeanValidationForm<Customer>(Customer.class);

客户 POJO:

public class Customer implements Serializable {
public static final String QUERY_ALL = "Customer.queryAll";
public static final String QUERY_BY_ID = "Customer.queryById";

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(length = 50, nullable = false)
private String name;
@Column(length = 50, nullable = false)
private String surname;
@Column(nullable = false)
private Boolean gender;

//getters and setters....
}

【问题讨论】:

标签: combobox vaadin


【解决方案1】:
    ComboBox comboBox = new ComboBox();
    comboBox.addItem(true);
    comboBox.setItemCaption(true, "Male");
    comboBox.addItem(false);
    comboBox.setItemCaption(false, "Feemale");

但我建议在此处使用枚举并将其保存为 @Enumerated(EnumType.STRING) 想象一下,如果有人新加入您的团队,他必须了解这些 1 和 0 的含义(在 DB 中)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-07
    • 1970-01-01
    • 1970-01-01
    • 2021-09-07
    • 2014-03-26
    • 1970-01-01
    • 2012-05-17
    相关资源
    最近更新 更多