0

I'm building a project based on the CRUD example of vaadin 8.

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.

This is the 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()));
AgamenonD2
  • 83
  • 1
  • 11
  • Please post your grid initialisation code. I guess you set the selection mode to single? Did you try `grid.deselectAll`? – Steffen Harbich Mar 15 '18 at 07:27
  • Code posted. With grid.desselectAll(); i get the same error: com.vaadin.event.ListenerMethod$MethodException: Invocation of method selectionChange in com.vaadin.ui.components.grid.SingleSelectionModelImpl$2$$Lambda$61/1409271157 failed. – AgamenonD2 Mar 15 '18 at 11:40

1 Answers1

0

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); gets a null pointer, even if i have instantiate a 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);
        }
AgamenonD2
  • 83
  • 1
  • 11