Vaadin 21 中的组合框不显示任何项目

ComboBox in Vaadin 21 shows no Items

我正在尝试将 ComboBox 与 Vaadin 21 一起使用。即使我使用了不同的填充变体,组合框也不会填充项目。也未设置占位符。 ComboBox 仍然带有虚线轮廓(我猜这意味着禁用)。

public class EventFormLayout extends HorizontalLayout {

    private final EventRepository eventRepository;

    private final ComboBox<String> timezone = new ComboBox<>("Timezone");;

    private Button cancel = new Button("Cancel");
    private Button save = new Button("Save");

    private Binder<Event> binder = new Binder(Event.class);

    @Autowired
    public EventFormLayout(Event event, EventRepository eventRepository) {
        this.eventRepository = eventRepository;

        ListDataProvider<String> tzDataProvider = DataProvider.ofCollection(ZoneId.getAvailableZoneIds());
        timezone.setLabel("Timezone");

        timezone.setItems(tzDataProvider);
        //timezone.setItems(ZoneId.getAvailableZoneIds());
        //timezone.setItems("UTC", "Europe/Berlin", "Europe/Paris");
        timezone.setPlaceholder("Timezone");
        timezone.setReadOnly(false);
        timezone.setEnabled(true);

        add(createTitle());
        add(createFormLayout());
        add(createButtonLayout());

        binder.bindInstanceFields(this);
        clearForm();

        cancel.addClickListener(e -> clearForm());
        save.addClickListener(e -> {
            eventRepository.save(binder.getBean());
            clearForm();
        });
    }

    private void clearForm() {
        binder.setBean(new Event());
    }

    private Component createTitle() {
        return new H3("Event");
    }

    private Component createFormLayout() {
        FormLayout formLayout = new FormLayout();
        formLayout.add(title, text, year, month, day, time, timezone);
        return formLayout;
    }

    private Component createButtonLayout() {
        HorizontalLayout buttonLayout = new HorizontalLayout();
        buttonLayout.addClassName("button-layout");
        save.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
        buttonLayout.add(save);
        buttonLayout.add(cancel);
        return buttonLayout;
    }

}

实体看起来像这样:

@Component
public class Event {

    @Transient @Getter
    private String timezone;

    public String setTimezone(String timezone) {
        this.timezone = timezone;
        return this.timezone;
    }

}

属性 是瞬态的,因为在我实际的 class 中,我对该值做了一些处理并将其保存到另一个 属性,但它是瞬态的事实没有任何意义解决问题,我试过了

这种情况下的问题是,setter return编辑了一些东西。这打破了自动绑定。现在有两种修复方法:要么让 setter return 什么都不存在,要么显式绑定 属性、

binder.forField(timezone).bind(Event::getTimezone, Event::setTimezone);
// before
binder.bindInstanceFields(this);