Set default value in ComboBox

Hi there!)
Using ComboBox I faced with a problem when i need to set default value after page rendered.
So, I tried to set default value using Id injected class of BeanItemContainer.
For example:
I have class Region (IdRegion, nmRegion). I add some Region’s into list (BeanItemContainer) and after all I need using some IdRegion to set default value of ComboBox.
Here the sketch for complete understanding…

BeanItemContainer<Region> items = new BeanItemContainer<Region>(Region.class); Region region = new Region(); region.setIdRegion(new BigDecimal(1)); region.setNmRegion("Moscow"); items.addBean(region); region = new Region(); region.setIdRegion(new BigDecimal(2)); region.setNmRegion("London"); items.addBean(region); ComboBox cb = new ComboBox("City: ", items); cb.setNullSelectionAllowed(false); cb.setItemCaptionMode(ItemCaptionMode.PROPERTY); cb.setItemCaptionPropertyId("nmRegion"); cb.setValue(region.getIdRegion()); //Here (or not) i need to pass some IdRegion //cb.select(region.getIdRegion()); How can i do that in Vaadin?
PS: Who familiar with JSF it is the same as SelectItem…

You need to create list of Regions, add all from the list to bean container and select one ofe them:

cb.setValue(london)

Agata, I khow this…) but the question was about posibility to do that using item Id, not name.

Just imagine situation when you have identical names and different Id’s, and you have to choose one of them using special Id to identify item…

Hi Alexander,

why do you want to use an id? You have a BeanItemContainer so you should use a Region object to set the value. You should implement correctly your equals() and hashCode methods and everything should be fine.

So use BeanContainer (instead of BeanItemContainer) with regionId as BeanIdProperty.

Hi Wolfgang!
Because logicaly it’s the right way to use an Id to identify row…

Agata,
Many Thanks for tip. That’s what I need!)