简体   繁体   English

Vaadin网格清除选择行

[英]Vaadin grid clear selection row

I'm building a project based on the CRUD example of vaadin 8. 我正在基于Vaadin 8的CRUD示例构建项目。

I have a grid that opens a form on the right side of my page, this form has a cancel button that close this form and clear the grid selection. 我有一个网格可以在页面右侧打开一个表单,该表单具有一个取消按钮,可以关闭该表单并清除网格选择。

I'm getting this error: 我收到此错误:

com.vaadin.event.ListenerMethod$MethodException: Invocation of method selectionChange in com.vaadin.ui.components.grid.SingleSelectionModelImpl$2$$Lambda$352/1190062771 failed. com.vaadin.event.ListenerMethod $ MethodException:调用方法selection.com.vaadin.ui.components.grid.SingleSelectionModelImpl $ 2 $$ Lambda $ 352/1190062771中的更改​​失败。

This is the stackTrace: 这是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)

Any idea? 任何想法? My object is not null. 我的对象不为空。

    public void clearSelection() {
       try {
            grid.getSelectionModel().deselectAll();
       } catch (Exception e) {
        e.printStackTrace();
       }
     }

My grid init code on the view class: 我在视图类上的网格初始化代码:

 grid = new GridViagem();
        grid.setDataProvider(dataProvider);
        grid.asSingleSelect().addValueChangeListener(
                event -> viewLogic.rowSelected(event.getValue()));

Found the problem, i had a function that is called every time a row is selected 发现问题,我有一个函数,每次选择一行时都会调用

 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);
}

For some reason, when my entity is null, the binder.readBean(product); 由于某些原因,当我的实体为null时,bind.readBean(product); gets a null pointer, even if i have instantiate a product = new Product(); 即使我实例化了一个product = new Product(),也得到一个空指针。

On the example i got the code the entity has default values, so i changed the code to: 在示例中,我获得了实体具有默认值的代码,因此我将代码更改为:

        if (viagem == null) {
            viagem = new Viagem();
            currentViagem = viagem;
            binderViagem.removeBean();
        } else {
            currentViagem = viagem;
            binderViagem.readBean(viagem);
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM