Well, I am not an expert, but I have used TwinColSelect in my project and it works just fine. Logically, my code is pretty similar to yours. However, I hesitate that u have populated the possible variants for your TwinColSelect. In other words - filled the container with some possible data.
public TeamSelect(String caption)
{
super(caption);
setHeight("100%");
setWidth("100%");
setImmediate(true);
ApplicationController.setCurrentNamespace("....");
final List<Worker> availableWorkers = EntityFetcher
.fetchEntitiesList(Worker.class);
container = new BeanItemContainer<Worker>(availableWorkers);
setContainerDataSource(container);
setItemCaptionPropertyId("fullName");
}
Thats the proto of the class that I use. Maybe it’ll help.
thanks for your answer. But my case is slightly different because I do not set the data container for myself. Instead of that I use a
BeanItem based form and the related field factory.
There must be (or maybe not?) an automatic matching between bean field and form. But how to build this field?
Well, probably you misunderstand the way this field works. The contents of your property inside of the bean represent the VALUE of the TwinColSelect. But the value is just the subset of possible variants. In your case the set of possibles is empty. That is why you don’t see anything in your TwinColSelect.
I also use this for the form that represents the project. TwinColSelect is used for the team field. There is a number of employees, but only some of them are taking part in this or that project. But you can always add or remove somebody. Thus, my TwinColSelect is populated with the whole crew and the value of it - is the set of workers from the team-field of the current BeanItem.
You are probably close. Using Set for both the getter/setter in the bean is key to getting and setting the values of the selected items.
When you build the TwinColSelect, you need to specify the possible values and labels that should be shown. It is easier when the display label and value are the same, but I created mine using something like:
private TwinColSelect createSelectBox(String vaadinMessageCaption) {
TwinColSelect selectList = new TwinColSelect(vaadinApp.getMsg(vaadinMessageCaption));
selectList.setWidth(100, UNITS_PERCENTAGE);
// Set all the possible values
for( int i=0; i < allIds.length; ++i ) {
selectList.addItem(allIds[ i ]
);
}
// Associate labels with our ID values
selectList.setItemCaptionMode(TwinColSelect.ITEM_CAPTION_MODE_EXPLICIT);
for( int i=0; i < allIds.length; ++i ) {
selectList.setItemCaption(allIds[ i ]
, allNames[ i ]
.toString());
}
selectList.setRows( Math.min(allIds.length,5) );
selectList.setNullSelectionAllowed(true);
selectList.setMultiSelect(true);
return selectList;
}
I think if the values set as items are the same as the labels that should be displayed, you don’t need to do the mapping (associate labels with our ID values) and setItemCaptionMode as it’s the default. But in my case above, the value is a unique ID, and the labels are the “name” of the item.
Well, yeah. That what i was talking about. But in my case i have some other bean objects as a possible values for TwinColSelect. So instead of setting the label for every single value setItemCaptionPropertyId(…) could be used.