При запуске приложения получаю ошибку:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'com.github.steed777.redsoft.redsoft.view.MainView':
Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'employeeAccountingEditor' defined in file [C:\MavenProject\redsoft\target\classes\com\github\steed777\redsoft\redsoft\components\EmployeeAccountingEditor.class]:
Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [com.github.steed777.redsoft.redsoft.components.EmployeeAccountingEditor]:
Constructor threw exception; nested exception is java.lang.IllegalStateException:
Property type 'java.lang.Long' doesn't match the field type 'java.lang.String'. Binding should be configured manually using converter.
Вот Editor:
@SpringComponent
@UIScope
public class EmployeeAccountingEditor extends VerticalLayout implements KeyNotifier {
private final EmployeeRepository repository;
private EmployeeAccounting accounting;
private TextField fio = new TextField("","ФИО");
private TextField pos = new TextField("","Должность");
private TextField email = new TextField("","Электронная почта");
private TextField phone = new TextField("","Телефон");
private TextField salary = new TextField("","Зарплата");
private Button save = new Button("Сохранить", VaadinIcon.CHECK.create());
private Button cancel = new Button("Отменить");
private Button delete = new Button("Удалить", VaadinIcon.TRASH.create());
private HorizontalLayout actions = new HorizontalLayout(save, cancel, delete);
private Binder<EmployeeAccounting> binder = new Binder<>(EmployeeAccounting.class);
@Setter
private ChangeHandler changeHandler;
public interface ChangeHandler {
void onChange();
}
@Autowired
public EmployeeAccountingEditor(EmployeeRepository repository) {
this.repository = repository;
add(fio, pos, email, phone, salary, 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 -> editEmployee(accounting));
setVisible(false);
}
private void delete() {
repository.save(accounting);
changeHandler.onChange();
}
private void save() {
repository.delete(accounting);
changeHandler.onChange();
}
public void editEmployee(EmployeeAccounting emp) {
if (emp == null) {
setVisible(false);
return;
} if (emp.getId() != null) {
this.accounting = repository.findById(emp.getId()).orElse(emp);
} else {
accounting = emp;
}
binder.setBean(this.accounting);
setVisible(true);
fio.focus();
}
}
А вот View:
@Route("")
public class MainView extends VerticalLayout {
private final EmployeeRepository repository;
private final Grid<EmployeeAccounting> grid;
private final TextField filter;
private final Button addNewBtn;
private final EmployeeAccountingEditor editor;
@Autowired
public MainView(EmployeeRepository repository, EmployeeAccountingEditor editor){
this.repository = repository;
this.grid = new Grid<>(EmployeeAccounting.class);
this.editor = editor;
this.filter = new TextField();
this.addNewBtn = new Button("Новый сотрудник", VaadinIcon.PLUS.create());
HorizontalLayout action = new HorizontalLayout(filter, addNewBtn);
filter.setPlaceholder("Поиск");
filter.setValueChangeMode(ValueChangeMode.EAGER);
filter.addValueChangeListener(e -> listEmployees(e.getValue()));
add(action, grid, editor);
grid.asSingleSelect().addValueChangeListener(e -> {
editor.editEmployee(e.getValue());
});
addNewBtn.addClickListener(e -> editor.editEmployee(new EmployeeAccounting()));
editor.setChangeHandler(() -> {
editor.setVisible(false);
listEmployees(filter.getValue());
});
listEmployees("");
}
private void listEmployees(String name) {
if(name.isEmpty()) {
grid.setItems(this.repository.findAll());
} else {
grid.setItems(this.repository.findByName(name));
}
}