Reputation: 425
I have a POJO which has gender value of customers as Boolean. I haveto make a combobox in a form which is data source is Customer type. How can I make the combobox have "Male" and "Female" choices which will be binded to Boolean values.
Thanks. Form Code:
Form customerForm= new BeanValidationForm<Customer>(Customer.class);
Customer 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....
}
Upvotes: 1
Views: 1508
Reputation: 2173
ComboBox comboBox = new ComboBox();
comboBox.addItem(true);
comboBox.setItemCaption(true, "Male");
comboBox.addItem(false);
comboBox.setItemCaption(false, "Feemale");
But I would recommend using an enum here and save it as @Enumerated(EnumType.STRING) Imagine if someone new enters your team, he'll have to learn what these 1 and 0 mean (in DB).
Upvotes: 4