TwinColSelect no values in right box

The TwinColSelect is not setting any values in the right box: the selected items. The items in the left box are displayed fine.

This is how the TwinColSelect is set inside a class that implements FormFieldFactory:


TwinColSelect rolesSelection = new TwinColSelect();
rolesSelection.setRows(5);
rolesSelection.setNullSelectionAllowed(false);
rolesSelection.setMultiSelect(true);
rolesSelection.setImmediate(true);
rolesSelection.setLeftColumnCaption("Available roles");
rolesSelection.setRightColumnCaption("Selected roles");
rolesSelection.setWidth("350px");
rolesSelection.setItemCaptionMode(TwinColSelect.ITEM_CAPTION_MODE_PROPERTY);
rolesSelection.setItemCaptionPropertyId("role");

// Set the left box
BeanContainer<String,UserRole> beanContainer = new BeanContainer<String, UserRole>(UserRole.class);
beanContainer.setBeanIdProperty("id");
beanContainer.setBeanIdResolver(new BeanIdResolver<String, UserRole>() {
    private static final long serialVersionUID = 1L;
    public String getIdForBean(UserRole userRole) {
        return userRole.getId();
    }
});
List<UserRole> roles = ops.getUserRoleDao().findAll();
beanContainer.addAll(roles);
rolesSelection.setContainerDataSource(beanContainer);

// Log the UserRoles from the DAO
for (UserRole r : roles) {
    LOGGER.debug("role hashcode: {}", r.hashCode());
}

com.vaadin.data.util.BeanItem bi = (com.vaadin.data.util.BeanItem)item;
UserAccount bean = (UserAccount)bi.getBean();
rolesSelection.setValue(bean.getUserRoles());

// Log the UserRoles from the UserAccount
for (UserRole r : bean.getUserRoles()) {
    LOGGER.debug("connected role hashcode: {}", r.hashCode());
}

As far as I know UserAccount and UserRole have valid equals() en hashtag() methods. I’m logging the hashcode of the UserRole objects. I can see that they match for some UserRoles, so the objects are equal and should be moved to the right box.

The solution was to update this piece of code:


        	beanContainer.setBeanIdResolver(new BeanIdResolver<UserRole, UserRole>() {
                private static final long serialVersionUID = 1L;

				public UserRole getIdForBean(UserRole userRole) {
					return userRole;
				}
            });