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.

ComponentRenderer for Grid-Cells doesn't create the Components

Michail Klimenkow
5 years ago May 22, 2016 12:47pm

Hi everybody, 

I want to use the Addon ComponentRenderer: https://vaadin.com/directory#!addon/componentrenderer
It renders standard components in a Grid, so you can build a cell with a text and a picture in one Gridcell for example.
But all my tries are not working. I just get an empty Grid as result.
I am thankful for any help or advice. Thanks!

package view;

import java.util.ArrayList;

import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.server.FontAwesome;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Component;
import com.vaadin.ui.Grid;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;

import controller.TippappManager;
import entities.*;
import model.UserDaten;
import de.datenhahn.vaadin.componentrenderer.grid.ComponentGenerator;
import de.datenhahn.vaadin.componentrenderer.grid.ComponentGridDecorator;

public class ClassicGrid extends VerticalLayout {

    public ClassicGrid (TippappManager manager, UserDaten userDaten) {
        setSizeFull();
        setMargin(true);
        setSpacing(true);

        Grid grid = new Grid();
        grid.setContainerDataSource(new BeanItemContainer<Spiel>(Spiel.class));
        ComponentGridDecorator<Spiel> componentGridDecorator = new ComponentGridDecorator<>(grid, Spiel.class);
        
        int turnierID = userDaten.getUserTippgruppeByID(manager.getCurrentTippgruppe()).getTurnierId();
        ArrayList<Spiel> offeneSpiele = userDaten.getSpiele().get(turnierID);

        componentGridDecorator.addAll(offeneSpiele);

        grid.setSizeFull();
        grid.setEditorEnabled(true);
        grid.setEditorBuffered(false);

        ComponentGenerator<Spiel> generatorIcon = new ComponentGenerator<Spiel>() {
            @Override
            public Component getComponent(Spiel bean) {
                return new Label(FontAwesome.HOURGLASS_2.getHtml(), ContentMode.HTML);
            }
        };

        ComponentGenerator<Spiel> generatorText = new ComponentGenerator<Spiel>() {
            @Override
            public Component getComponent(Spiel bean) {
                return new Label(FontAwesome.HOURGLASS_2.getHtml(), ContentMode.HTML);
            }
        };

        componentGridDecorator.addComponentColumn("icon", generatorIcon);
        componentGridDecorator.addComponentColumn("text", generatorText);

        // always display the details column
        grid.setFrozenColumnCount(1);

        grid.setColumns( "icon", "text");

        addComponent(grid);
//        setExpandRatio(grid, 1.0f);
    }

}
Saif Idrees
4 years ago May 25, 2017 8:15am