Value / Caption of a Select component

Hi !

Let’s say I have a MyBean class which contains a reference to another class “MyRefBean” identifier.


public class MyBean {
 [...]

  private String myRefBeanId;
 [...]

}

I created a form to fill a MyBean object, myRefBeanId being bounded through a Select component. Is this the best (only ?) way to use the Select component to display a caption which is different from the value ?


Select select = new Select("My Select component");

List<MyRefBean> beans = getMyRefBeanCollection();
BeanItemContainer<String> container = new BeanItemContainer<String>(String.class);
for (MyRefBean refBean : beans ) {
	BeanItem<String> beanItem = container.addBean(refBean.getValueProperty());
	beanItem.addItemProperty("displayName",new ObjectProperty(refBean.getDisplayProperty()));
}
select.setContainerDataSource(container);
select.setItemCaptionPropertyId("displayName");

Thanks.

You can also use a pure select:


Select select=new Select();
for(Foo foo: foos)
{
  select.addItem(foo);
  select.setItemCaption(foo,foo.getBar());
}

…thanks. Actually I found such sample in my code that I wrote few days ago… :wacko: