绑定布尔值在Vaadin

问题描述:

的组合框我有具有客户为布尔的性别价值POJO。我必须以数据源为客户类型的形式创建组合框。 如何使组合框有“男”和将被绑定到布尔值“女”的选择。绑定布尔值在Vaadin

谢谢。 表格代号:

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.... 
} 
+0

看一看:https://vaadin.com/book/-/page/components.selecting.html你的要求有描述。你必须添加你的物品(真,假),然后添加一个itemDescription。 – zip 2012-08-06 14:13:50

ComboBox comboBox = new ComboBox(); 
    comboBox.addItem(true); 
    comboBox.setItemCaption(true, "Male"); 
    comboBox.addItem(false); 
    comboBox.setItemCaption(false, "Feemale"); 

但我会建议在这里使用一个枚举并将其保存为@Enumerated(EnumType.STRING) 试想一下,如果有人进入新的团队,他必须知道这些1和0是什么意思(在DB中)。