public class ComboBoxComponent extends VerticalLayout { public ComboBoxComponent() { BeanItemContainer<Person> dataSource = new BeanItemContainer<>(HasCaption.class); ComboBox comboBox = new ComboBox(); comboBox.setItemCaptionMode(AbstractSelect.ItemCaptionMode.PROPERTY); // use a fake property which will get identified by the getter comboBox.setItemCaptionPropertyId("caption"); addComponent(comboBox); comboBox.setContainerDataSource(dataSource); Random random = new Random(); for (int i = 0; i < 10; i++) { dataSource.addBean(new Person("Name " + i, "Surname " + i, random.nextInt(99) + 1)); } } }
protected AbstractField createTextField() { ComboBox out = new ComboBox(); out.setItemCaptionPropertyId("title"); out.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY); out.setFilteringMode(Filtering.FILTERINGMODE_CONTAINS); out.setNullSelectionAllowed(false); //TODO container = new IndexedContainer(); // container.addContainerProperty("id", String.class, ""); container.addContainerProperty("title", String.class, ""); out.setContainerDataSource(container); return out; }
BeanItemContainer<Person> container = new BeanItemContainer<Person>(Person.class); container.addAll(myPersonList); ComboBox combobox = new ComboBox(); combobox.setContainerDataSource(container); combobox.setItemCaptionMode(Select.ITEM_CAPTION_MODE_PROPERTY); combobox.setItemCaptionPropertyId("name"); // the person's name field will be shown on the UI // imho if you want to add a static text (String) into a container // which populated with Person objects then you have to make a fake Person object Person staticText = new Person(); staticText.setName("My static text"); combobox.addItem(staticText); // if you want to specify the index of the item, add them one by one in for cycle // and insert the static text item in the appropritate place
private void buildUI() { combo = new ComboBox(null, container); combo.setImmediate(true); combo.setNullSelectionAllowed(false); combo.setWidth(200 + "px"); combo.setId(ID.getId(Optional.empty(), this, combo)); combo.setContainerDataSource(container); // Sets the combobox to show a certain property as the item caption combo.setItemCaptionPropertyId(LocaleContainer.PropertyName.NAME); combo.setItemCaptionMode(ItemCaptionMode.PROPERTY); // Sets the icon to use with the items combo.setItemIconPropertyId(LocaleContainer.PropertyName.FLAG); combo.setValue(currentLocale.getLocale() .toLanguageTag()); combo.addValueChangeListener(this); }
/* Creating a container, with a property of "name". Item Id is a number, here. Can be anything (unique). * Alternatively, you could use the IndexedContainer to generate it's own ItemId : * cityContainer.getItem(cityContainer.addItem()).getItemProperty("name").setValue("New York"); */ IndexedContainer cityContainer = new IndexedContainer(); cityContainer.addContainerProperty("name", String.class, null); cityContainer.addItem(1).getItemProperty("name").setValue("New York"); cityContainer.addItem(2).getItemProperty("name").setValue("Turku"); cityContainer.addItem(3).getItemProperty("name").setValue("Paris"); cityContainer.addItem(4).getItemProperty("name").setValue("Zanzibar"); cityContainer.addItem(5).getItemProperty("name").setValue("Turin"); cityContainer.addItem(6).getItemProperty("name").setValue("London"); cityContainer.getItem(cityContainer.addItem()).getItemProperty("name").setValue("New York"); /* Lets sort the container on ascending name*/ cityContainer.sort(new Object[]{"name"}, new boolean[]{true}); /* Here's a comboBox that uses that container, where we are using the "name" property as the item caption */ ComboBox comboBox = new ComboBox("City", cityContainer); comboBox.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY); comboBox.setItemCaptionPropertyId("name");
m_viewSelector.setItemCaptionMode(ItemCaptionMode.EXPLICIT); m_typeHelper = createTypeHelper(); m_typeHelper.precomputeTypeLists(
combobox.setItemCaptionMode(AbstractSelect.ItemCaptionMode.PROPERTY); combobox.setItemCaptionPropertyId("name"); // the person's name field will be shown on the UI combobox.addValueChangeListener(new Property.ValueChangeListener() {
this.sortComboBox.setTextInputAllowed(false); this.sortComboBox.setFilteringMode(FilteringMode.OFF); this.sortComboBox.setItemCaptionMode(AbstractSelect.ItemCaptionMode.PROPERTY); this.sortComboBox.setItemCaptionPropertyId(SortKeyContainer.DESCRIPTION_PROPERTY); this.sortComboBox.setImmediate(true);
this.sortComboBox.setTextInputAllowed(false); this.sortComboBox.setFilteringMode(FilteringMode.OFF); this.sortComboBox.setItemCaptionMode(AbstractSelect.ItemCaptionMode.PROPERTY); this.sortComboBox.setItemCaptionPropertyId(SortKeyContainer.DESCRIPTION_PROPERTY); this.sortComboBox.setImmediate(true);