ComboBox items with custom caption

Hi,
I am trying to create a ComboBox where the caption for each item is a combination of properties, like object.title + object.subobject.name
The items that are added to the ComboBox are returned from a backend query wrapped in BeanItem (using LazyQueryContainer).
Is there a way I can set the captions for individual items?

I tried by setting the item caption mode to ITEM_CAPTION_MODE_EXPLICIT and doing comboBox.setItemCaption in the ItemSetChangeListener on both the ComboBox and the Container but that doesn’t seem to work
How do I do this? Appreciate any help, thanks.

Hello,

I managed to solve this problem in the following way.

UserContainer is of type BeanItemContainer.

            cboxUser = new ComboBox(AppData.getMessage("user"));
	cboxUser.setContainerDataSource(AppData.getUserContainer());
	cboxUser.setItemCaptionMode(Select.ITEM_CAPTION_MODE_EXPLICIT);	
	cboxUser.addListener(new ItemSetChangeListener() {
		
		public void containerItemSetChange(ItemSetChangeEvent event) {
			UserContainer container = (UserContainer)((ComboBox)event.getContainer()).getContainerDataSource();
			Collection<UserVO> users = container.getItemIds();
			for (Iterator iterator = users.iterator(); iterator.hasNext();) {
				UserVO user = (UserVO) iterator.next();
				cboxUser.setItemCaption(user, user.getFirstName() + " " + user.getName());
			}			
		}
	});
	cboxUser.setInputPrompt(AppData.getMessage("combobox.user"));
	cboxUser.setImmediate(true);
	cboxUser.setRequired(true);

I hope the example is explicit enough.

Hello,
if yet need solve…


public class MyContainer implements Serializable {

    private Long id;
    private Long name;

...

    public String toString() {
        return getName() + " " + getId();
    }
}

ComboBox cb = new ComboBox(“Caption”, myContainer);
cb.setItemCaptionMode(ItemCaptionMode.ITEM);

Hi, is it posible to use html as the item caption for comboBox ?

Hello,
How can I develope a right to left supported web site in vaadin?

Thank you , now it has served me very helpful / Muchas Gracias, hoy me ha servido de mucha ayuda!!!