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 14 Error: cannot infer type arguments for com.vaadin.flow.data.rende

Teodor Iancu
3 years ago Aug 18, 2019 3:26pm

I'm trying to iterate over a HashMap to display the content in Vaadin14 Grid to look like this:

that's the java class:

public class MyClass extends VerticalLayout {

    // Dummy Data
    LocalDate date1 = LocalDate.now();
    LocalDate date2 = LocalDate.now();
    LocalDate date3 = LocalDate.now();
    Boolean[] isPresent1 = {true, false, false, true, true, false, false, true, true};
    Boolean[] isPresent2 = {true, false, false, true, true, false, false, true, true};
    Boolean[] isPresent3 = {true, false, false, true, true, false, false, true, true};

    Map<LocalDate, Boolean[]> trainingsMap = new HashMap<>();

    Grid<Map.Entry<LocalDate, Boolean[]>> grid = new Grid<>();

    Icon icon;

    public MyClass() {
        // in reality data come from Spring Data - Repository - Service
        trainingsMap.put(date1, isPresent1);
        trainingsMap.put(date2, isPresent2);
        trainingsMap.put(date3, isPresent3);

        for (Map.Entry<LocalDate, Boolean[]> map : trainingsMap.entrySet()) {
            grid.addColumn(new ComponentRenderer<Component, Map<LocalDate, Boolean[]>>(createIsPresent(map.getValue())));
                   // .setHeaderRenderer(new LocalDateTimeRenderer<>(map.getKey(), "dd/MM HH:mm:ss"))); // 
        }

        grid.setItems(trainingsMap.entrySet());
        add(grid);
    }

    private Component createIsPresent(Boolean[] isPresent) {
        for (Boolean b : isPresent) {
            if (b) {
                icon = UIUtils.createPrimaryIcon(VaadinIcon.CHECK);
            }
        }
        return icon;
    }

}

Error: Cannot resolve constructor com.vaadin.flow.data.renderer.ComponentRenderer<>

Is this possible at all or am I doing something fundamentally wrong?

Last updated on Aug, 18th 2019
Stuart Robinson
3 years ago Aug 18, 2019 8:13pm

Have you tried it with the arguments Component, Map<LocalDate, Boolean[]> ?

i.e.

        for (Map.Entry<LocalDate, Boolean[]> map : trainingsMap.entrySet()) {
            grid.addColumn(new ComponentRenderer<Comnponent, Map<LocalDate, Boolean[]>>(createIsPresent(map.getValue()))
                    .setHeaderRenderer(new LocalDateTimeRenderer<>(map.getKey(), "dd/MM HH:mm:ss")));
        }

S.

Teodor Iancu
3 years ago Aug 18, 2019 9:36pm
Stuart Robinson
3 years ago Aug 18, 2019 9:38pm
Teodor Iancu
3 years ago Aug 18, 2019 9:53pm
Stuart Robinson
3 years ago Aug 18, 2019 10:57pm
Teodor Iancu
3 years ago Aug 19, 2019 3:08pm
Stuart Robinson
3 years ago Aug 19, 2019 4:14pm
Teodor Iancu
3 years ago Aug 19, 2019 5:13pm
Stuart Robinson
3 years ago Aug 19, 2019 7:46pm
Teodor Iancu
3 years ago Aug 19, 2019 7:55pm