3

I am using Vaadin 8 for Tabular data representation with dynamic bean. so i have to define logical filter on column.

For that i need column datatype from grid or column object. Is there any way to get data types of column?

In Vaadin 7 i can get using container.getType(columnName)

Uttam Kasundara
  • 237
  • 3
  • 13

2 Answers2

1

In the Vaadin 8 data binding model, the property type is not explicitly known by the UI component (in your case Grid). This information should come from your domain model.

If difficult to retrieve 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();
Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
rmuller
  • 12,062
  • 4
  • 64
  • 92
0

You can get the type of the column, when setting the styleGenerator for the column. For example, I do the following to set a specific style if the column is a 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's a way to get it "outside" of the style generator.

jrf
  • 490
  • 5
  • 16
  • In this case you get the type of the *instance*. Not always the same as the property type of the bean (although it is assignable from) – rmuller Aug 11 '17 at 07:27
  • 1
    While clever and possibly useful, this is not a `getter` so much as a `guesser`. – Basil Bourque Sep 05 '17 at 20:25