2012-08-06 141 views
1

的組合框我有具有客戶爲布爾的性別價值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

回答

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

但我會建議在這裏使用一個枚舉並將其保存爲@Enumerated(EnumType.STRING) 試想一下,如果有人進入新的團隊,他必須知道這些1和0是什麼意思(在DB中)。