Combobox binding not working correctly?

I’m currently facing a problem where my form doesn’t bind correctly with my entity.

My Entity has a category attribute:

    @Nullable
    private String category;

    public @Nullable String category() {
        return this.category;
    }

    public void category(@Nullable String category) {
        this.category = category;
    }

Inside my form I got a ComboBox for selecting the category. It displays all existing categories and allows the creation of new ones.

final ComboBox<String> category = new ComboBox<>("Category");
        category.setItems(categories); // categories = list from db query
        category.setAllowCustomValue(true);
        category.setRequired(false);
binder.bind(category, Entry::category, Entry::category);

When saving the entity, all values are written except for the category which stays null.

    private void validateAndSave() {
        if (!binder.validate().hasErrors()) {
            try {
                if (entry.created() == null) {
                    entry.created(LocalDateTime.now());
                    entry.owner(UI.getCurrent().getSession().getAttribute("username").toString());
                }
                binder.writeBean(entry);
                entry.updated(LocalDateTime.now());
                System.out.println("Saving entry: " + entry); // DEBUG
                fireEvent(new SaveEvent(this, binder.getBean()));
            } catch (Exception e) {
                Notification.show("Unable to save entry", 3000, Notification.Position.TOP_END);
            }
        } else {
            Notification.show("Invalid!", 3000, Notification.Position.TOP_END);
        }
    }

Saving entry: Entry{id=1, title='Title', shortDescription='Summary', description='Description', priority=Very high, status=Work in progress, category='null', created=2024-02-28T20:37:15.243710, updated=2024-02-28T20:44:00.368615700, dueDate=2024-03-02T05:00, owner='user'}

The project is open source, the code for the classes in question are:

https://github.com/LeStegii/vaadin-todo/blob/master/src/main/java/io/github/lestegii/todo/data/entity/Entry.java

https://github.com/LeStegii/vaadin-todo/blob/master/src/main/java/io/github/lestegii/todo/component/EntryFormDialog.java#L55

If you enter a custom value, you have to store it yourself in the dedicated listerner, see the example code of it in the docs

Ah, so I have to add the entry to the combobox items?
image.png

Yes

Ok, I got it working, thanks for your help.

I tried that before even without looking at the wiki but it didn’t work.
Since the code was identical to the wiki, I went back a few steps and sure enough, it was my mistake. The list was immutable and I just wasn’t able to read the error correctly :man_facepalming: