Search code examples
vaadinvaadin-flowvaadin-gridvaadin14

Problem with multiple grid header rows in a Vaadin 14 application with classpath scanning disabled


When I use appendHeaderRow() or prependHeaderRow() to add one or more additional header rows to a grid in my Vaadin 14 application, the grid still only displays one header row. I'm almost certain that I understand why this is happening, but the solution isn't clear.

In my project, I've disabled classpath scanning and I'm manually instantiating and invoking the initializers used by Vaadin, as described in this example. I have a class that implements ServletContextListener and invokes the initializers, just like the VaadinInitializer class from the example.

In order to get the header rows to display correctly, I believe I have to pass ColumnGroup.class to the DevModeInitializer, as it corresponds with the <vaadin-grid-column-group> element that I see in the grid's HTML when I add an additional row to the header. I've had to do this with many other Vaadin classes in order to get them to display correctly, including Grid and GridSelectionColumn. The problem is that unlike these other classes, the ColumnGroup class isn't public, so I'm unable to import it and pass it to the initializer.

Does anyone know of any workarounds, or is it not possible to get multiple grid header rows to work correctly with my project configuration?


Solution

  • The inability to reference non-public classes seems to be an omission in the whole idea with how to avoid classpath scanning.

    I believe you can work around the issue by creating a dummy component class with the same resource annotations as ColumnGroup and then use that class with the initializer. This should work since this part of Vaadin only cares about which annotations are found, but it doesn't matter where they are found.