Vaadin 8 Grid issue

Good evening,

I am having a serious issue with grid data. The first time grid loads properly. When i search the next customer grid data doesn’t change.
I displayed the
list
and i noticed the new data being populated in the list however I am not able to paint the new grid but the page refresh works just fine.

Please help !!!

Code:

public void [b]

BuildUI
[/b](String key) {
System.out.println(“CustomerService() - BuildUI”);
setSizeFull();
addStyleName(“crud-view”);
HorizontalLayout topLayout = createTopBar();

    grid = new CustomerGrid();

    VerticalLayout barAndGridLayout = new VerticalLayout();
    barAndGridLayout.addComponent(topLayout);
    barAndGridLayout.addComponent(grid);
    barAndGridLayout.setSizeFull();
    barAndGridLayout.setExpandRatio(grid, 1);
    barAndGridLayout.setStyleName("crud-main-layout");
    
    updateList();
    
    addComponent(barAndGridLayout);
}

public void updateList() {
    System.out.println("CustomerService() - updateList");
    List<Customer> customers = null;
    CustomerService service = CustomerService.getInstance(key);
    customers = service.findAll(filter.getValue());
    
    grid.setItems(customers);
    System.out.println(customers.toString());   <== This display shows the newly fetched data.
}

Hi,

At least this code snippet doesn’t show anything immediately wrong. Can you share your CustomerGrid implementation as well?

-Olli

Attahced are CustomerView.java and CustomerService.java files.
38901.java (8.7 KB)
38902.java (4.07 KB)

Thanks Olli, here is my code. Also, I attached the CustomerView.java file for your reference.

CustomerGrid.java

package com.sunpower.infolease.customer;

import com.vaadin.ui.Grid;
import com.vaadin.ui.renderers.NumberRenderer;

/**

  • Grid of products, handling the visual presentation and filtering of a set of

  • items. This version uses an in-memory data source that is suitable for small

  • data sets.
    */
    public class CustomerGrid extends Grid {

    private static final long serialVersionUID = 1L;

    public CustomerGrid() {
    setSizeFull();

     addColumn(Customer::getCcan, new NumberRenderer()).setCaption("CCAN");
     addColumn(Customer::getName).setCaption("Customer Name");
     addColumn(Customer::getEmail).setCaption("Email ID");
     addColumn(Customer::getPhone).setCaption("Phone");
     addColumn(Customer::getAddress).setCaption("Address");
    

    }

    public Customer getSelectedRow() {
    return asSingleSelect().getValue();
    }

    public void refresh(Customer product) {
    getDataCommunicator().refresh(product);
    }

}

Customer.java

package com.sunpower.infolease.customer;

import java.io.Serializable;

public class Customer implements Serializable, Cloneable {

private static final long serialVersionUID = 1L;

private long ccan;
private String name    = "";
private String address = "";
private String phone   = "";
private String email   = "";

public Customer(long ccan, String name, String email, String phone, String address) {
     this.ccan    = ccan;
     this.name    = name;
     this.email   = email;
     this.phone   = phone;
     this.address = address;
}

public Customer() {
    // TODO Auto-generated constructor stub
}

public long getCcan() {
    return ccan;
}

public void setCcan(long ccan) {
    this.ccan = ccan;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

public String getPhone() {
    return phone;
}

public void setPhone(String phone) {
    this.phone = phone;
}

public String getAddress() {
    return address;
}

public void setAddress(String address) {
    this.address = address;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

@Override
public Customer clone() throws CloneNotSupportedException {
    return (Customer) super.clone();
}

@Override
public String toString() {
    return "Customer:: ID="+this.ccan+" Name=" + this.name + " phone=" + this.phone + " email=" + this.address + " address=" + this.address;
}

}

One way to updae the content of the Grid via DataProvider is by adding/removing items in underlying collection and applying refreshAll() method of the DataProvider.

Hi Srini,

I tested your app out (as much as I could) and looks like the problem is in your backend or the CustomerService. I don’t know the details, but after modifying the code to work without the real backend, I was able to update my CustomerGrid with new (randomly generated) entries whenever the ValueChangeEvent of the filter TextField fires. So the Vaadin code seems to work ok.

-Olli