I’m using an beanContainer to fill an combobox en to show the “loginName” as the selection field.
DTO
public class UserDTO extends Observable implements Serializable {
private static final long serialVersionUID = 1L;
private int userId;
private String loginName;
private String password;
private String firstName;
private String lastName;
private AddressDTO address;
private boolean privacyAddress;
private String pictureLocation;
private Date birthDate;
private RightDTO right;
private String email;
private String telephone;
private boolean privacyTelephone;
private String mobile;
private boolean privacyMobile;
private int minLimit;
private int maxLimit;
private int balance;
private boolean active;
...
//filling the combobox with UserDTO's by BeanContainer
BeanContainer<String, UserDTO> beanContainer = new BeanContainer<String, UserDTO>(
UserDTO.class);
beanContainer.setBeanIdProperty("loginName");
cmbSolver.setImmediate(true);
cmbSolver.setNewItemsAllowed(false);
cmbSolver.setNullSelectionAllowed(false);
cmbSolver.setContainerDataSource(beanContainer);
cmbSolver.setItemCaptionMode(ItemCaptionMode.ID);
cmbSolver.setItemCaptionPropertyId("loginName");
ArrayList<UserDTO> solvers = pc.retrieveSolvers();
for (int i = 0; i < solvers.size(); i++) {
System.out.println("solver = " + solvers.get(i));
}
beanContainer.addAll(solver);
I would like to create an combobox where I can select the UserDTO. The name in the combobox that I would like to show is the LoginName of the UserDTO, but I would like to retrieve the selected UserDTO depending on what is selected in the Combobox. When I use combobox.getValue() I get a String and not the UserDTO. What is the best way to do so?