bean实例化失败;嵌套异常;SpringBoot和Vaadin



我要坦率地说,我是Java的新手,尤其是SpringBoot。我一直在模仿Vaadin CRM教程应用程序,并根据我的需求进行了小客户化。当我尝试登录时,它会抛出以下错误,我无法弄清楚,所以我只想复制粘贴整个堆栈:


尝试导航到"时出现异常,异常消息为"创建文件[C:\Users\nikol\Desktop\vaadin-crm\vaadin crm\target\classes\com\vaadin\tutorial\crm\UI\views\list\listView.class]中定义的名为"listView"的bean时出错":通过构造函数实例化bean失败;嵌套异常为org.springframework.beans.BeanInstanceException:未能实例化[com.vadin.tutorial.crm.UI.views.list.ListView]:构造函数引发异常;嵌套异常为java.lang.IollegalStateException:属性类型"java.lang.Integer"与字段类型"java.lang.String"不匹配。应使用转换器手动配置绑定

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'listView' defined in file [C:UsersnikolDesktopvaadin-crmvaadin-crmtargetclassescomvaadintutorialcrmUIviewslistListView.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.vaadin.tutorial.crm.UI.views.list.ListView]: Constructor threw exception; nested exception is java.lang.IllegalStateException: Property type 'java.lang.Integer' doesn't match the field type 'java.lang.String'. Binding should be configured manually using converter.
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:315)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:296)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1354)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1204)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:353)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveNamedBean(DefaultListableBeanFactory.java:1273)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveNamedBean(DefaultListableBeanFactory.java:1234)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveBean(DefaultListableBeanFactory.java:494)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:349)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:342)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1172)
at com.vaadin.flow.spring.SpringInstantiator.getOrCreate(SpringInstantiator.java:106)
at com.vaadin.flow.di.Instantiator.createRouteTarget(Instantiator.java:160)
at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.lambda$getRouteTarget$1(AbstractNavigationStateRenderer.java:137)
at java.base/java.util.Optional.orElseGet(Optional.java:362)
at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.getRouteTarget(AbstractNavigationStateRenderer.java:136)
at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.sendBeforeEnterEventAndPopulateChain(AbstractNavigationStateRenderer.java:525)
at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.createChainIfEmptyAndExecuteBeforeEnterNavigation(AbstractNavigationStateRenderer.java:505)
at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.handle(AbstractNavigationStateRenderer.java:222)
at com.vaadin.flow.router.Router.handleNavigation(Router.java:249)
at com.vaadin.flow.router.Router.navigate(Router.java:220)
at com.vaadin.flow.router.Router.navigate(Router.java:186)
at com.vaadin.flow.router.Router.initializeUI(Router.java:93)
at com.vaadin.flow.server.BootstrapHandler.initializeUIWithRouter(BootstrapHandler.java:1532)
at com.vaadin.flow.server.BootstrapHandler.createAndInitUI(BootstrapHandler.java:1525)
at com.vaadin.flow.server.BootstrapHandler.synchronizedHandleRequest(BootstrapHandler.java:475)
at com.vaadin.flow.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40)
at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1547)
at com.vaadin.flow.server.VaadinServlet.service(VaadinServlet.java:247)
at com.vaadin.flow.spring.SpringServlet.service(SpringServlet.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:710)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:457)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:352)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
at org.springframework.web.servlet.mvc.ServletForwardingController.handleRequestInternal(ServletForwardingController.java:141)
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:177)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:52)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1060)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:962)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:626)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:327)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:115)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:81)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:119)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:126)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:81)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:149)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:218)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:212)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:103)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:89)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
at org.springframework.security.web.header.HeaderWriterFilter.doHeadersAfter(HeaderWriterFilter.java:90)
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:75)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:110)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:80)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:55)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:211)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:183)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:358)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:271)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:893)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1707)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.vaadin.tutorial.crm.UI.views.list.ListView]: Constructor threw exception; nested exception is java.lang.IllegalStateException: Property type 'java.lang.Integer' doesn't match the field type 'java.lang.String'. Binding should be configured manually using converter.
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:225)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:117)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:311)
... 120 more
Caused by: java.lang.IllegalStateException: Property type 'java.lang.Integer' doesn't match the field type 'java.lang.String'. Binding should be configured manually using converter.
at com.vaadin.flow.data.binder.Binder.bindProperty(Binder.java:2859)
at com.vaadin.flow.data.binder.Binder.lambda$null$26(Binder.java:2759)
at com.vaadin.flow.data.binder.Binder.handleProperty(Binder.java:2948)
at com.vaadin.flow.data.binder.Binder.lambda$bindInstanceFields$27(Binder.java:2757)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.reduce(ReferencePipeline.java:563)
at com.vaadin.flow.data.binder.Binder.bindInstanceFields(Binder.java:2761)
at com.vaadin.tutorial.crm.UI.views.list.LivreForm.<init>(LivreForm.java:44)
at com.vaadin.tutorial.crm.UI.views.list.ListView.<init>(ListView.java:63)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:212)
... 122 more

堆栈中提到的ListView如下:


package com.vaadin.tutorial.crm.UI.views.list;
import com.vaadin.flow.component.Key;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.button.ButtonVariant;
import com.vaadin.flow.component.dependency.CssImport;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.value.ValueChangeMode;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.server.PWA;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.vaadin.tutorial.crm.backend.entity.Campus;
import com.vaadin.tutorial.crm.backend.entity.Livre;
import com.vaadin.tutorial.crm.backend.entity.Stock;
import com.vaadin.tutorial.crm.backend.service.CampusService;
import com.vaadin.tutorial.crm.backend.service.LivreService;
import com.vaadin.tutorial.crm.UI.views.list.LivreForm;
import com.vaadin.tutorial.crm.UI.views.list.MainLayout;
/**
* A sample Vaadin view class.
* <p>
* To implement a Vaadin view just extend any Vaadin component and
* use @Route annotation to announce it in a URL as a Spring managed
* bean.
* Use the @PWA annotation make the application installable on phones,
* tablets and some desktop browsers.
* <p>
* A new instance of this class is created for every new user and every
* browser tab/window.
*/
@Component
@Scope("prototype")
@Route(value = "", layout = MainLayout.class)
@PageTitle("Livres | ENI Ecole Informatique")
public class ListView extends VerticalLayout {
LivreService livreService;
Grid<Livre> grid = new Grid<>(Livre.class);
TextField filterText = new TextField();
LivreForm form1;




public ListView(LivreService livreService, CampusService campusService) {
this.livreService = livreService;
addClassName("list-view"); 
setSizeFull(); 
configureGrid(); 


form1 = new LivreForm(campusService.findAll());
form1.addListener(LivreForm.SaveEvent.class, this::saveLivre); 
form1.addListener(LivreForm.DeleteEvent.class, this::deleteLivre); 
form1.addListener(LivreForm.CloseEvent.class, e -> closeEditor());
add(grid); 
add(filterText, grid, form1);
Div content = new Div(grid, form1); 
content.addClassName("content");
content.setSizeFull();
add(getToolbar(), content); 
updateList();
closeEditor();
}

private void configureGrid() {
grid.addClassName("livre-grid");
grid.setSizeFull();
grid.removeColumnByKey("campus");
grid.removeColumnByKey("stock");
grid.setColumns("titreLivre", "description", "auteur", "refeni", "isbn", "categorie", "status"); 
grid.addColumn(livre -> { 
Campus campus = livre.getCampus();
return campus == null ? "-" : campus.getNomCampus();
}).setHeader("Campus");
grid.addColumn(livre -> { 
Stock stock = livre.getStock();
return stock == null ? "-" : stock.getQuantiteStock();
}).setHeader("Stock");

grid.getColumns().forEach(col -> col.setAutoWidth(true));
grid.asSingleSelect().addValueChangeListener(event -> 
editLivre(event.getValue()));
}

public void editLivre(Livre livre) { 
if (livre == null) {
closeEditor();
} else {
form1.setLivre(livre);
form1.setVisible(true);
addClassName("editing");
}
}

private void saveLivre(LivreForm.SaveEvent event) {
livreService.save(event.getLivre());
updateList();
closeEditor();
}
private void deleteLivre(LivreForm.DeleteEvent event) {
livreService.delete(event.getLivre());
updateList();
closeEditor();
}

private void closeEditor() {
form1.setLivre(null);
form1.setVisible(false);
removeClassName("editing");
}

private HorizontalLayout getToolbar() {
filterText.setPlaceholder("Filtrer par titre ou auteur..."); 
filterText.setClearButtonVisible(true); 
filterText.setValueChangeMode(ValueChangeMode.LAZY); 
filterText.addValueChangeListener(e -> updateList()); 

Button addLivreButton = new Button("Ajouter livre");
addLivreButton.addClickListener(click -> addLivre()); 
HorizontalLayout toolbar = new HorizontalLayout(filterText, addLivreButton); 
toolbar.addClassName("toolbar");
return toolbar;
}

void addLivre() {
grid.asSingleSelect().clear(); 
editLivre(new Livre()); 
}

private void updateList() {
grid.setItems(livreService.findAll(filterText.getValue()));
}


}

和LivreForm是这样的:


package com.vaadin.tutorial.crm.UI.views.list;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.ComponentEvent;
import com.vaadin.flow.component.ComponentEventListener;
import com.vaadin.flow.component.Key;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.button.ButtonVariant;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.formlayout.FormLayout;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.textfield.EmailField;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.BeanValidationBinder;
import com.vaadin.flow.data.binder.Binder;
import com.vaadin.flow.data.binder.ValidationException;
import com.vaadin.flow.shared.Registration;
import com.vaadin.tutorial.crm.backend.entity.Livre;
import com.vaadin.tutorial.crm.backend.entity.Livre.Categorie;
import com.vaadin.tutorial.crm.backend.entity.Campus;
import com.vaadin.tutorial.crm.backend.entity.Stock;
import java.util.List;
public class LivreForm extends FormLayout{
TextField titreLivre = new TextField("titreLivre");
TextField description = new TextField("description");
TextField auteur = new TextField("auteur");
TextField refeni = new TextField("refeni");
TextField isbn = new TextField("isbn");
ComboBox<Livre.Categorie> categorie = new ComboBox<>("Categorie");
ComboBox<Livre.Status> status = new ComboBox<>("Status");
ComboBox<Stock> stock = new ComboBox<>("Stock");
ComboBox<Campus> campus = new ComboBox<>("Campus");

Button save = new Button("Save"); 
Button delete = new Button("Delete");
Button close = new Button("Cancel");
Binder<Livre> binder = new BeanValidationBinder<>(Livre.class);
private Livre livre;

public LivreForm(List<Campus> campuses) {
addClassName("livre-form");
binder.bindInstanceFields(this);
campus.setItems(campuses);
campus.setItemLabelGenerator(Campus::getNomCampus);
status.setItems(Livre.Status.values());
categorie.setItems(Livre.Categorie.values());
add(titreLivre,
description,
auteur,
refeni,
isbn,
categorie,
status,
campus,
stock,
createButtonsLayout()); 
}

public void setLivre(Livre livre) {
this.livre = livre; 
binder.readBean(livre); 
}




private Component createButtonsLayout() {
save.addThemeVariants(ButtonVariant.LUMO_PRIMARY); 
delete.addThemeVariants(ButtonVariant.LUMO_ERROR);
close.addThemeVariants(ButtonVariant.LUMO_TERTIARY);
save.addClickShortcut(Key.ENTER); 
close.addClickShortcut(Key.ESCAPE);

save.addClickListener(event -> validateAndSave()); 
delete.addClickListener(event -> fireEvent(new DeleteEvent(this, livre))); 
close.addClickListener(event -> fireEvent(new CloseEvent(this))); 

binder.addStatusChangeListener(e -> save.setEnabled(binder.isValid()));
return new HorizontalLayout(save, delete, close); 
}

private void validateAndSave() {
try {
binder.writeBean(livre); 
fireEvent(new SaveEvent(this, livre)); 
} catch (ValidationException e) {
e.printStackTrace();
}
}

public static abstract class LivreFormEvent extends ComponentEvent<LivreForm> {

private Livre livre;
protected LivreFormEvent(LivreForm source,Livre contact) { 
super(source, false);
this.livre = livre;
}
public Livre getLivre() {
return livre;
}
}
public static class SaveEvent extends LivreFormEvent {
SaveEvent(LivreForm source, Livre livre) {
super(source, livre);
}
}
public static class DeleteEvent extends LivreFormEvent {
DeleteEvent(LivreForm source, Livre livre) {
super(source, livre);
}
}
public static class CloseEvent extends LivreFormEvent {
CloseEvent(LivreForm source) {
super(source, null);
}
}
public <T extends ComponentEvent<?>> Registration addListener(Class<T> eventType,
ComponentEventListener<T> listener) { 
return getEventBus().addListener(eventType, listener);
}

}

希望您能告诉我第63行和第44行是如何关联的,以及它们的问题是什么,因为这个特定的代码猴子被难住了。

问题是当您尝试在第62行添加form1时,它没有初始化。

Caused by: java.lang.NullPointerException: Component to add cannot be null
at java.base/java.util.Objects.requireNonNull(Objects.java:233)
at com.vaadin.flow.component.HasComponents.add(HasComponents.java:53)
at com.vaadin.tutorial.crm.UI.views.list.ListView.<init>(ListView.java:62)

使用此链接,它提供了最佳解决方案https://vaadin.com/docs/v8/framework/datamodel/datamodel-forms#datamodel.forms.conversion

相关内容

  • 没有找到相关文章