Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
ComboBox setValue
I have a problem for the management of a comboBox (cb)
List profili = profiliService.findAll(b);
container = new BeanItemContainer<>(Profili.class, profili);
...
cb.setContainerDataSource(container);
cb.setItemCaptionMode(ItemCaptionMode.PROPERTY);
cb.setItemCaptionPropertyId("[b]profdescr[/b]");
cb.setTextInputAllowed(false);
cb.setInputPrompt("No selected profile");
cb.setNullSelectionAllowed(false);
cb.setNewItemsAllowed(false);
cb.setImmediate(true);
inside comboBox cb I view the profiles properly
Within a table I insert users with profdescr field
utentiService = new UtentiService();
List utenti = utentiService.findAll(b);
tab.setContainerDataSource(new BeanItemContainer<>(Utenti.class, utenti));
tab.setVisibleColumns("uuser", "[b]profdescr[/b]", "uemail");
tab.setColumnReorderingAllowed(true);
tab.setSelectable(true);
tab.setImmediate(true);
tab.setColumnHeader("uuser", "User");
tab.setColumnHeader("profdescr", "Profilo");
tab.setColumnHeader("uemail", "E-Mail");
tab.addItemClickListener(new ItemClickEvent.ItemClickListener() {
@Override
public void itemClick(ItemClickEvent itemClickEvent) {
if (itemClickEvent.isDoubleClick()) {
System.out.println(itemClickEvent.getItemId().toString());
updateForm(itemClickEvent);
} else
vCampi.setVisible(false);
}
});
on itemClickEvent I read the selected data of the item and fill the textfield. cb.setValue (and cb.select) does not work
private void updateForm(ItemClickEvent itemClickEvent) {
if (itemClickEvent.getItemId().toString().equals("")) {
...
} else {
Utenti utente = (Utenti) itemClickEvent.getItemId();
tb_user.setValue(utente.getUuser());
tb_pwd.setValue(utente.getUpwd());
tb_email.setValue(utente.getUemail());
Item item = itemClickEvent.getItem();
cb.setImmediate(true);
cb.setValue(item.getItemProperty("profdescr").getValue());
}
}
grazie
The combobox is using a BeanItemContainer so you should give an instace of your Profili class to select or setValue.
And in Profili class you should correctly implement equals and hashcode
HTH
Marco
thank you, I solved this way. It will not be the cleanest solution but it works
Iterator it = cb_profilo.getItemIds().iterator();
while(it.hasNext()){
Profili id = (Profili) it.next();
if (id.getProfdescr().equals(utente.getProfdescr()))
{
cb_profilo.select(id);
break;
}
}