Home > Mobile >  how to get the value of selected data in combo box?
how to get the value of selected data in combo box?

Time:07-25

//this is my textfield

TextField quantityStock = new TextField("Available Stock");

//this is my combo box

ComboBox<Item> itemList = new ComboBox<>("Item");

//this is my code

public SoldItemForm(List<Item> allItems) {
        addClassName("item-form");

        // * item field 
        itemList.setItems(allItems);
        itemList.setItemLabelGenerator(Item::getItemName)
        itemList.addValueChangeListener(event->{
            if (event.getValue() != null){
                quantityStock.setValue(event.toString());
                
            }
        });
        

        // * Item Stock 
        quantityStock.setReadOnly(true);

        add(itemList, quantityStock);

    }

I want to display the selected item name in combo box to my textfield but this line is diplaying: ComponentValueChangeEvent[source=com.vaadin.flow.component.combobox.ComboBox@5744eaab, value = com.smart.inventory.application.data.entities.Item@81, oldValue = null]

CodePudding user response:

Replace event.toString() with event.getValue().getItemName(). Currently you are printing the whole event instead of the event's value/item.

  • Related