alejandro-du / crudui

Automatically generate CRUD-like Vaadin views for any Java Bean
https://vaadin.com/directory#!addon/crud-ui-add-on
Apache License 2.0
86 stars 54 forks source link

The grid is empty, even though items exist in the data source in version 3.6.0 in a Spring Boot project #39

Closed mrts closed 5 years ago

mrts commented 5 years ago

Thanks for GridCrud, it is really useful and the API is elegant!

Version 2.3.0 worked very well in a library management app prototype that I created with Vaadin 8, but version 3.6.0 displays an empty grid with similar code in a Spring Boot project with Vaadin 10.

Here's the screenshot that shows that grid contains 5 items (I clicked on refresh to trigger the notification) but does not display them;

screenshot-localhost-8080-2018 12 16-22-31-03

Here's the relevant snippet:

@Route
public class MainView extends VerticalLayout {

    private Repository<Book> bookRepository;

    @Autowired
    public MainView(DataPopulator dataPopulator, Repository<Book> bookRepository) {
        this.bookRepository = bookRepository;
        dataPopulator.fillDatabase();
        add(createBookGridCrud());
    }

    private GridCrud<Book> createBookGridCrud() {
        final GridCrud<Book> crud = new GridCrud<>(Book.class);

        crud.setFindAllOperation(bookRepository::findAll);
        crud.setAddOperation(bookRepository::add);
        crud.setUpdateOperation(bookRepository::update);
        crud.setDeleteOperation(bookRepository::delete);

        // I also tried with crud.setSizeFull(); to no avail
        return crud;
    }
}

The full project is here:
https://gitlab.com/library-manager/library-manager-admin-vaadin/

Any idea why the grid stays empty?

mrts commented 5 years ago

The problem was with altered behavior of VerticalLayout and Grid in Vaadin 10, I had to use setSizeFull() in MainView to make the grid visible:

    @Autowired
    public MainView(DataPopulator dataPopulator, Repository<Book> bookRepository) {
        this.bookRepository = bookRepository;
        dataPopulator.fillDatabase();
        add(createBookGridCrud());
        setSizeFull(); // <---
    }

Seems obvious in the hindsight, but this was not necessary in Vaadin 8.

Vaadin 10 GridCrud is really nice, thank you!