Having trouble getting combobox.select() to work

I am writing a basic CRUD app using Hibernate MySQL.
Adding new records is fine but I’m having some trouble getting an existing record’s value to appear as the selected item by default when editing an existing record.

[code]
Criteria criteriaz = session.createCriteria(Organisation.class);
final List orgList = criteriaz.list();
BeanItemContainer srcOrgs = new BeanItemContainer(Organisation.class);
srcOrgs.addAll(orgList);

organisationId.setInvalidAllowed(false);
organisationId.setNullSelectionAllowed(false);
organisationId.setContainerDataSource(srcOrgs);
organisationId.setItemCaptionMode(ItemCaptionMode.PROPERTY);
organisationId.setItemCaptionPropertyId(“name”);

for (Organisation mOrg : orgList) {
if (mOrg.getRowid().equals(activity.getOrganisationId()))
mOrgID = mOrg.getName();
}

organisationId.select(mOrgID);
[/code]What am I doing wrong here?

For a
BeanItemContainer
, the item is its own item ID. You are using it’s name property.

Thanks for the reply. This is my very first Vaadin app so I am trying to learn the ropes.
I am a bit confused.
When I created the combobox I set

organisationId.setItemCaptionPropertyId("name"); and I then used a ValueChangeListener to record the id (rowid).

I followed your suggestion and set

organisationId.select("id"); and also tried

organisationId.select(activity.getOrganisationId());

but neither worked. What am I doing wrong?

It was only the last line in your above code sample that was the issue.

organisationId.select(mOrgID); takes a
String
but needs an instance of
Organization
that is present in your container because the container is of type
BeanItemContainer
. The method
setItemCaptionPropertyId
ist just for presentation. It doesn’t affect what is considered the item ID. In this case the value of each
Organization
's name is used to populate the combo box.

So in the absence of knowing more details the following should work

Organization org = null;
for (Organisation mOrg : orgList) {
                    if (mOrg.getRowid().equals(activity.getOrganisationId())) 
                        org = mOrg;  
                }
organisationId.select(org);

Thank you so much.
This works perfectly!

Cheers. Glad it helped!