Dinamically inject Css in a Grid for setClassNameGenerator to work

Basically, I have a function generating a string from a DataBase that corresponds to a bunch of css classes and I want to apply these classes to my Grid rows, depending on the content of the row using setClassNameGenerator. How do I do it?

Is there a better way to generate the CSS file from a DB?
Are there different ways to style my Rows?

For context, the function generates a string that is like this:

     background-color: retrievedColor;
     color: retrievedColor;

     background-color: retrievedColor;
     color: retrievedColor;

even being able to iterate over each cell in a row and set a className to it would work… but apparently that’s not possible in Vaadin?
This is killing me. Shadow Dom in Java with hidden JS is insane

I solved with a bit of an abominable code:

  commessaGrid.getColumns().forEach(column -> {
        column.setRenderer(new ComponentRenderer<>(item -> {
            Div cellContent = new Div();
            if (column.getHeaderText().equals("Descrizione")) {
            } else if (column.getHeaderText().equals("Stato")) {
            }else if (column.getHeaderText().equals("Cliente")) {
            } else  cellContent.setText(String.valueOf(item.getId()));
            return cellContent;

Basically, I created a custom Componentrender for each of the Data Provider elements and set inline style… sad…

That’s the only solution from the server side if you need 100% dynamic values. (Even you could still replace components with lit renderer but I have a feeling you don’t like them anyway)

Note: one hack could be also to create a styles tag with the element API but has to be managed as well

I am incredibly new to Vaadin so any suggestion is accepted… Thank you very much!