diff --git a/src/main/java/com/flowingcode/vaadin/addons/gridexporter/CsvStreamResourceWriter.java b/src/main/java/com/flowingcode/vaadin/addons/gridexporter/CsvStreamResourceWriter.java index 6a9a450..fe8b291 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/gridexporter/CsvStreamResourceWriter.java +++ b/src/main/java/com/flowingcode/vaadin/addons/gridexporter/CsvStreamResourceWriter.java @@ -22,8 +22,6 @@ import com.opencsv.CSVWriter; import com.vaadin.flow.component.grid.Grid; -import com.vaadin.flow.data.binder.BeanPropertySet; -import com.vaadin.flow.data.binder.PropertySet; import com.vaadin.flow.server.VaadinSession; import java.io.IOException; import java.io.OutputStream; @@ -92,11 +90,8 @@ public void accept(OutputStream out, VaadinSession session) throws IOException { } } - @SuppressWarnings("unchecked") private String[] buildRow(T item) { - if (exporter.propertySet == null) { - exporter.propertySet = (PropertySet) BeanPropertySet.get(item.getClass()); - } + if (exporter.getColumns().isEmpty()) throw new IllegalStateException("Grid has no columns"); String[] result = new String[exporter.getColumns().size()]; diff --git a/src/main/java/com/flowingcode/vaadin/addons/gridexporter/DocxStreamResourceWriter.java b/src/main/java/com/flowingcode/vaadin/addons/gridexporter/DocxStreamResourceWriter.java index 1c19908..6608745 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/gridexporter/DocxStreamResourceWriter.java +++ b/src/main/java/com/flowingcode/vaadin/addons/gridexporter/DocxStreamResourceWriter.java @@ -23,8 +23,6 @@ import com.vaadin.flow.component.grid.ColumnTextAlign; import com.vaadin.flow.component.grid.Grid; import com.vaadin.flow.component.grid.Grid.Column; -import com.vaadin.flow.data.binder.BeanPropertySet; -import com.vaadin.flow.data.binder.PropertySet; import com.vaadin.flow.data.provider.DataProvider; import com.vaadin.flow.server.VaadinSession; import java.io.IOException; @@ -180,16 +178,13 @@ private void fillData(XWPFTable table, XWPFTableCell dataCell, DataProvider) BeanPropertySet.get(item.getClass()); - } + if (exporter.getColumns().isEmpty()) { throw new IllegalStateException("Grid has no columns"); } diff --git a/src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java b/src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java index dab01be..0914ee1 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java +++ b/src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java @@ -56,8 +56,6 @@ import com.vaadin.flow.component.grid.ColumnTextAlign; import com.vaadin.flow.component.grid.Grid; import com.vaadin.flow.component.grid.Grid.Column; -import com.vaadin.flow.data.binder.BeanPropertySet; -import com.vaadin.flow.data.binder.PropertySet; import com.vaadin.flow.data.provider.DataProvider; import com.vaadin.flow.function.ValueProvider; import com.vaadin.flow.server.VaadinSession; @@ -237,11 +235,8 @@ private int fillData( return dataRange.getLastRow(); } - @SuppressWarnings("unchecked") private void buildRow(T item, Sheet sheet, Cell startingCell) { - if (exporter.propertySet == null) { - exporter.propertySet = (PropertySet) BeanPropertySet.get(item.getClass()); - } + if (exporter.getColumns().isEmpty()) { throw new IllegalStateException("Grid has no columns"); } diff --git a/src/main/java/com/flowingcode/vaadin/addons/gridexporter/GridExporter.java b/src/main/java/com/flowingcode/vaadin/addons/gridexporter/GridExporter.java index 20dd6a8..1011723 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/gridexporter/GridExporter.java +++ b/src/main/java/com/flowingcode/vaadin/addons/gridexporter/GridExporter.java @@ -30,6 +30,7 @@ import com.vaadin.flow.component.grid.Grid.Column; import com.vaadin.flow.component.html.Anchor; import com.vaadin.flow.component.orderedlayout.FlexComponent.JustifyContentMode; +import com.vaadin.flow.data.binder.BeanPropertySet; import com.vaadin.flow.data.binder.PropertyDefinition; import com.vaadin.flow.data.binder.PropertySet; import com.vaadin.flow.data.renderer.BasicRenderer; @@ -110,7 +111,7 @@ public class GridExporter implements Serializable { String footersPlaceHolder = "${footers}"; List> columns; - PropertySet propertySet; + private PropertySet propertySet; Map additionalPlaceHolders = new HashMap<>(); @@ -226,6 +227,9 @@ Object extractValueFromColumn(T item, Column column) { // if there is a key, assume that the property can be retrieved from it if (value == null && column.getKey() != null) { + if (propertySet == null) { + propertySet = (PropertySet) BeanPropertySet.get(item.getClass()); + } Optional> propertyDefinition = propertySet.getProperty(column.getKey()); if (propertyDefinition.isPresent()) {