ComboBox setItem from Object return only the end of data (Vaadin 24.1)

Hi, i want to create ComboBox that contain ‘code’ from Department Database,

this is the preload code for combobox

    private void populateDepartment(){
        cbSearchDepartment.clear();

        try {
            listDepartment = departmentService.getDepartmentListForComboBox(false);

            System.out.println(listDepartment.size());

            for (Department department : listDepartment) {
                cbSearchDepartment.setItems(department.getCode());
            }

            if (listDepartment.size() > 0)
                cbSearchDepartment.setValue(listDepartment.get(0).getCode());
        }catch(Exception ex) {
                ex.printStackTrace();
            }
    }

i test it with print size() of the listDepartment and it return the correct value, but the ComboBox is only show the last one of the database data, (‘ALL’ at the combobox can be set from the set value. see the image at the attachment)

thank you!

EDIT : i tried this method at Vaadin 8 and i dont have this issue at all
image.png

and this is data from Department table
image.png

setItems is not additiv, it replaces the current list and therefore only the last item(s) is/are present

is there any way to add all department without replace it?

setItems(listDepartment) is normally the way to go instead of iterating over it

i tried it but it returns the unique id instead of ‘code’ table
image.png

if i inisialize the listDepartment with get, i need to set int for which data

https://vaadin.com/docs/latest/components/combo-box it’s all described here with custom representations

If you really really only need the strings. Just do a department.stream(d->d.code).to list (pseudo code) and add this instead of the department list

ahh, i get it, its kinda different with Vaadin 8, i need to filter data first before importing the result to the combobox, thank you!