Vaadin: Как забиндить Set?

Есть сущность в бд

@Entity
public class Contact extends BaseEntity {
    private String surname;
    private String name;
    private String patronymic;
    @OneToMany(mappedBy = "contact", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    private Set<Phone> phones = new LinkedHashSet<>();
    @OneToMany(mappedBy = "contact", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    private Set<Email> emails = new LinkedHashSet<>();
    private String position;
    private String organisation;
    // Getters & Setters
}

Контакт может иметь несколько email

@Entity
public class Email extends BaseEntity {
    private String email;
    @ManyToOne
    @JoinColumn(name = "contact_id")
    private Contact contact;
}

Для изменения хочу использовать TextArea, где в каждой строке будет email.

@SpringComponent
@UIScope
public class ContactEditor extends VerticalLayout implements KeyNotifier {
    private static final Logger log = LoggerFactory.getLogger(ContactEditor.class);

    private ContactRepository repository;
    private Contact contact;

    TextField name = new TextField("Имя");
    TextField surname = new TextField("Фамилия");
    TextField patronymic = new TextField("Отчество");
    TextArea emails = new TextArea("Почта");
    TextField position = new TextField("Должность");
    TextField organisation = new TextField("Организация");
    Image photo = new Image();
    MemoryBuffer buffer = new MemoryBuffer();
    Upload upload = new Upload(buffer);

    Button save = new Button("Сохранить", VaadinIcon.CHECK.create());
    Button cancel = new Button("Отмена");
    Button delete = new Button("Удалить", VaadinIcon.TRASH.create());

    HorizontalLayout actions = new HorizontalLayout(save, cancel, delete, upload);
    Binder<Contact> binder = new Binder<>(Contact.class);
    private ChangeHandler changeHandler;

    @Autowired
    public ContactEditor(ContactRepository repository) {
        this.repository = repository;
        upload.setAcceptedFileTypes("image/jpeg", "image/png", "image/gif");

        add(name, surname, patronymic, emails, position, organisation, photo, actions);

        binder.bindInstanceFields(this);

        setSpacing(true);

        save.getElement().getThemeList().add("primary");
        delete.getElement().getThemeList().add("error");

        addKeyPressListener(Key.ENTER, e -> save());

        save.addClickListener(e -> save());
        delete.addClickListener(e -> delete());
        cancel.addClickListener(e -> editContact(contact));
        upload.addSucceededListener(event -> setUploadPhoto(event.getFileName()));
        setVisible(false);
    }
}

Метод binder.bindInstanceFields(this) выдает exception поскольку не может забиндить поле типа Set. Как можно реализовать подобное?


Ответы (0 шт):