Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Vaadin 8 Grid with Generic list

Nagaraj RC
5 years ago Mar 13, 2017 3:11pm

Hi i am using Vaadin 8.0.1

I am trying to make Vaadin grid common for all of my DataList
And trying to set the Generic Arraylist of Data to Grid its not showing anything to me.

Here is my Grid code.

public class VegaGrid<T> {

    private Grid<T> grid;
    private T t;
    private ArrayList<T> mParentDataList;

    public ArrayList<T> getParentDataList() {
        return mParentDataList;
    }

    public void setParentDataList(ArrayList<T> pParentDataList) {
        this.mParentDataList = pParentDataList;
        System.out.println("size=" + pParentDataList.size());//its printing the sie as 1001
        try {
            ListDataProvider<T> ldp = new ListDataProvider<>(pParentDataList);
            grid.setDataProvider(ldp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public VerticalLayout createControls() {
        VerticalLayout v = new VerticalLayout();
        try {
            grid = new Grid<T>();
            grid.setWidth("100%");
            grid.getColumns().stream().forEach(column -> column.setHidable(true));
            grid.setColumnReorderingAllowed(true);
            grid.setSelectionMode(SelectionMode.SINGLE);
            v.addComponent(grid);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return v;
    }
}

And Here i am calling the Grid by paasing Arralist of PersonData

ArrayList<PersonData> personDataList = new ArrayList<PersonData>();
            for (int i = 0; i <= 1000; i++) {
                PersonData p = new PersonData();
                p.setId(100);
                p.setName("AAA");
                p.setWeight(50.20);
                p.setDob(new Date());
                personDataList.add(p);
            }

VegaGrid<PersonData> vegaGrid = new VegaGrid<>();
 VerticalLayout v=vegaGrid.createControls();
 vegaGrid.setParentDataList(personDataList); // Here i am Passing the ListDAta
 addComponent(v);

I am getting the grid but not the data inside.
here i am attaching the screen shot

Regards
Nagaraj RC
 

Alexander Ley
5 years ago Mar 16, 2017 9:25am
Sangeeth S Kumar
1 year ago Jul 18, 2020 4:18pm