diff options
author | Artur Signell <artur@vaadin.com> | 2015-05-18 21:39:06 +0300 |
---|---|---|
committer | Mika Murtojarvi <mika@vaadin.com> | 2015-05-25 14:02:17 +0300 |
commit | bdb5dbff6663e92b08ab11303341f9990b008ec1 (patch) | |
tree | 63eef6fbd4bc7d8ab3dfd3e370f99c7c8b6d683c | |
parent | 0c4b02dad38a265b6fdd7d491164614902ec9c12 (diff) | |
download | vaadin-framework-bdb5dbff6663e92b08ab11303341f9990b008ec1.tar.gz vaadin-framework-bdb5dbff6663e92b08ab11303341f9990b008ec1.zip |
Handle generated empty string style names properly (#17335)
Change-Id: I7e1622e69be7ef5b6df641c0428a521623983e3e
4 files changed, 59 insertions, 3 deletions
diff --git a/server/src/com/vaadin/data/RpcDataProviderExtension.java b/server/src/com/vaadin/data/RpcDataProviderExtension.java index 5fb0742164..671226d4bc 100644 --- a/server/src/com/vaadin/data/RpcDataProviderExtension.java +++ b/server/src/com/vaadin/data/RpcDataProviderExtension.java @@ -835,7 +835,7 @@ public class RpcDataProviderExtension extends AbstractExtension { Object propertyId = column.getPropertyId(); cellReference.set(propertyId); String style = generator.getStyle(cellReference); - if (style != null) { + if (style != null && !style.isEmpty()) { if (cellStyles == null) { cellStyles = Json.createObject(); } @@ -853,7 +853,7 @@ public class RpcDataProviderExtension extends AbstractExtension { private void setGeneratedRowStyles(RowStyleGenerator generator, JsonObject rowObject) { String rowStyle = generator.getStyle(rowReference); - if (rowStyle != null) { + if (rowStyle != null && !rowStyle.isEmpty()) { rowObject.put(GridState.JSONKEY_ROWSTYLE, rowStyle); } } diff --git a/uitest/src/com/vaadin/tests/components/grid/GridHeaderStyleNames.java b/uitest/src/com/vaadin/tests/components/grid/GridHeaderStyleNames.java index 765cd01812..019850dabb 100644 --- a/uitest/src/com/vaadin/tests/components/grid/GridHeaderStyleNames.java +++ b/uitest/src/com/vaadin/tests/components/grid/GridHeaderStyleNames.java @@ -46,7 +46,7 @@ public class GridHeaderStyleNames extends AbstractTestUIWithLog { .createContainer(100)); ageHeaderCell = grid.getDefaultHeaderRow().getCell("age"); - + grid.getDefaultHeaderRow().setStyleName("foo"); headerRow = grid.prependHeaderRow(); mergedCityCountryCell = headerRow.join("city", "country"); mergedCityCountryCell.setText("Merged cell"); diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java index 83accfe370..0bb9a123d5 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java @@ -73,9 +73,13 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> { public static final String ROW_STYLE_GENERATOR_ROW_NUMBERS_FOR_3_OF_4 = "Row numbers for 3/4"; public static final String ROW_STYLE_GENERATOR_NONE = "None"; public static final String ROW_STYLE_GENERATOR_ROW_NUMBERS = "Row numbers"; + public static final String ROW_STYLE_GENERATOR_EMPTY = "Empty string"; + public static final String ROW_STYLE_GENERATOR_NULL = "Null"; public static final String CELL_STYLE_GENERATOR_NONE = "None"; public static final String CELL_STYLE_GENERATOR_PROPERTY_TO_STRING = "Property to string"; public static final String CELL_STYLE_GENERATOR_SPECIAL = "Special for 1/4 Column 1"; + public static final String CELL_STYLE_GENERATOR_EMPTY = "Empty string"; + public static final String CELL_STYLE_GENERATOR_NULL = "Null"; private static final int MANUALLY_FORMATTED_COLUMNS = 5; public static final int COLUMNS = 12; public static final int EDITABLE_COLUMNS = COLUMNS - 1; @@ -409,6 +413,22 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> { } } }); + rowStyleGenerators.put(ROW_STYLE_GENERATOR_EMPTY, + new RowStyleGenerator() { + + @Override + public String getStyle(RowReference rowReference) { + return ""; + } + }); + rowStyleGenerators.put(ROW_STYLE_GENERATOR_NULL, + new RowStyleGenerator() { + + @Override + public String getStyle(RowReference rowReference) { + return null; + } + }); cellStyleGenerators.put(CELL_STYLE_GENERATOR_NONE, null); cellStyleGenerators.put(CELL_STYLE_GENERATOR_PROPERTY_TO_STRING, new CellStyleGenerator() { @@ -434,6 +454,20 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> { return propertyId.toString().replace(' ', '_'); } }); + cellStyleGenerators.put(CELL_STYLE_GENERATOR_EMPTY, + new CellStyleGenerator() { + @Override + public String getStyle(CellReference cellReference) { + return ""; + } + }); + cellStyleGenerators.put(CELL_STYLE_GENERATOR_NULL, + new CellStyleGenerator() { + @Override + public String getStyle(CellReference cellReference) { + return null; + } + }); createSelectAction("Row style generator", "State", rowStyleGenerators, CELL_STYLE_GENERATOR_NONE, diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridCellStyleGeneratorTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridCellStyleGeneratorTest.java index 643c61d90a..f013b76075 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridCellStyleGeneratorTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridCellStyleGeneratorTest.java @@ -118,4 +118,26 @@ public class GridCellStyleGeneratorTest extends GridBasicFeaturesTest { private void selectCellStyleNameGenerator(String name) { selectMenuPath("Component", "State", "Cell style generator", name); } + + @Test + public void testEmptyStringStyleGenerator() { + setDebug(true); + openTestURL(); + selectCellStyleNameGenerator(GridBasicFeatures.CELL_STYLE_GENERATOR_EMPTY); + selectRowStyleNameGenerator(GridBasicFeatures.ROW_STYLE_GENERATOR_EMPTY); + + assertFalse("Error notification was present", + isElementPresent(NotificationElement.class)); + } + + @Test + public void testNullStringStyleGenerator() { + setDebug(true); + openTestURL(); + selectCellStyleNameGenerator(GridBasicFeatures.CELL_STYLE_GENERATOR_NULL); + selectRowStyleNameGenerator(GridBasicFeatures.ROW_STYLE_GENERATOR_NULL); + + assertFalse("Error notification was present", + isElementPresent(NotificationElement.class)); + } } |