我正在根据vaadin 8的CRUD示例构建一个项目。
我有一个网格打开页面右侧的表单,此表单有一个取消按钮,可以关闭此表单并清除网格选择。
我收到了这个错误:
com.vaadin.event.ListenerMethod $ MethodException:方法的调用 selectionChange in com.vaadin.ui.components.grid.SingleSelectionModelImpl $ 2 $$ LAMBDA $1190062771分之352 失败。
这是stackTrace:
com.vaadin.event.ListenerMethod$MethodException: Invocation of method selectionChange in com.vaadin.ui.components.grid.SingleSelectionModelImpl$2$$Lambda$352/1190062771 failed.
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:519)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:273)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:237)
at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:1014)
at com.vaadin.ui.components.grid.SingleSelectionModelImpl.setSelectedFromServer(SingleSelectionModelImpl.java:179)
at com.vaadin.ui.components.grid.SingleSelectionModelImpl.deselect(SingleSelectionModelImpl.java:90)
Caused by: java.lang.NullPointerException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
有什么想法吗?我的对象不是空的。
public void clearSelection() {
try {
grid.getSelectionModel().deselectAll();
} catch (Exception e) {
e.printStackTrace();
}
}
我在视图类上的网格初始化代码:
grid = new GridViagem();
grid.setDataProvider(dataProvider);
grid.asSingleSelect().addValueChangeListener(
event -> viewLogic.rowSelected(event.getValue()));
答案 0 :(得分:0)
发现问题,我每次选择一行时都会调用一个函数
public void editProduct(Product product) {
if (product == null) {
product = new Product();
}
currentProduct = product;
binder.readBean(product);
// Scroll to the top
// As this is not a Panel, using JavaScript
String scrollScript = "window.document.getElementById('" + getId()
+ "').scrollTop = 0;";
Page.getCurrent().getJavaScript().execute(scrollScript);
}
由于某种原因,当我的实体为null时,binder.readBean(product);得到一个空指针,即使我已实例化product = new Product();
在示例中,我获得了代码,实体具有默认值,因此我将代码更改为:
if (viagem == null) {
viagem = new Viagem();
currentViagem = viagem;
binderViagem.removeBean();
} else {
currentViagem = viagem;
binderViagem.readBean(viagem);
}