How do I get the column type of a Vaadin 8 grid?
2 answers
In the Vaadin 8 data binding model, the property type is not explicitly known to the UI component (in your case Grid
). This information should come from your domain model.
If you find it difficult to get from your domain model, you can do:
// instead of new Grid(beanType)
PropertySet<YourBeanType> ps = BeanPropertySet.get(beanType);
Grid g = new Grid(ps);
...
// get the property type
// okay, this is ugly, but you get the idea
Class<?> type = ps.getProperty(yourPropertyName).get().getType();
+2
source to share
You can get the column type when setting styleGenerator
for a column. For example, I do the following to set a specific style if a column BigDecimal
:
Grid.Column c = grid.getColumn("id");
c.setStyleGenerator(obj -> {
Object value = c.getValueProvider().apply(obj);
if (value instanceof BigDecimal) {
return "align-right";
}
return null;
});
I'm not sure if there is a way to get "outside" the style generator.
0
source to share