diff options
author | Artur Signell <artur@vaadin.com> | 2014-12-08 20:41:40 +0200 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2014-12-10 19:35:32 +0000 |
commit | d5682f7fbfb7b0c4fa4848c6b96faa7c27d32363 (patch) | |
tree | ae9313da05d68786073e6515fc33473bc24d83aa | |
parent | d80b1b2ee2378d8d51a81b22abbaa8b60d548cf4 (diff) | |
download | vaadin-framework-d5682f7fbfb7b0c4fa4848c6b96faa7c27d32363.tar.gz vaadin-framework-d5682f7fbfb7b0c4fa4848c6b96faa7c27d32363.zip |
Render empty cell instead of stopping rendering if a converter is missing
Change-Id: I64ef6bf6b89e2bfe9704cc81f3caf3b0f4271656
4 files changed, 98 insertions, 6 deletions
diff --git a/server/src/com/vaadin/data/RpcDataProviderExtension.java b/server/src/com/vaadin/data/RpcDataProviderExtension.java index c4a4e3f22b..aa0d6b3716 100644 --- a/server/src/com/vaadin/data/RpcDataProviderExtension.java +++ b/server/src/com/vaadin/data/RpcDataProviderExtension.java @@ -25,6 +25,8 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; import com.google.gwt.thirdparty.guava.common.collect.BiMap; import com.google.gwt.thirdparty.guava.common.collect.HashBiMap; @@ -38,6 +40,7 @@ import com.vaadin.data.Property.ValueChangeEvent; import com.vaadin.data.Property.ValueChangeListener; import com.vaadin.data.Property.ValueChangeNotifier; import com.vaadin.data.util.converter.Converter; +import com.vaadin.data.util.converter.Converter.ConversionException; import com.vaadin.server.AbstractExtension; import com.vaadin.server.ClientConnector; import com.vaadin.server.KeyMapper; @@ -436,8 +439,8 @@ public class RpcDataProviderExtension extends AbstractExtension { * @param removedPropertyIds * the property ids that have been removed from the container */ - public void propertiesRemoved(@SuppressWarnings("unused") - Collection<Object> removedPropertyIds) { + public void propertiesRemoved( + @SuppressWarnings("unused") Collection<Object> removedPropertyIds) { /* * no-op, for now. * @@ -948,12 +951,21 @@ public class RpcDataProviderExtension extends AbstractExtension { try { presentationValue = presentationType.cast(modelValue); } catch (ClassCastException e) { - throw new Converter.ConversionException( + ConversionException ee = new Converter.ConversionException( "Unable to convert value of type " + modelValue.getClass().getName() + " to presentation type " + presentationType.getName() + ". No converter is set and the types are not compatible."); + if (presentationType == String.class) { + // We don't want to throw an exception for the default cause + // when one column can't be rendered. Just log the exception + // and let the column be empty + presentationValue = (T) ""; + getLogger().log(Level.SEVERE, ee.getMessage(), ee); + } else { + throw ee; + } } } else { assert presentationType.isAssignableFrom(converter @@ -968,4 +980,9 @@ public class RpcDataProviderExtension extends AbstractExtension { return encodedValue; } + + private static Logger getLogger() { + return Logger.getLogger(RpcDataProviderExtension.class.getName()); + } + } diff --git a/server/tests/src/com/vaadin/tests/server/component/grid/RendererTest.java b/server/tests/src/com/vaadin/tests/server/component/grid/RendererTest.java index 608559a059..c2779bfe89 100644 --- a/server/tests/src/com/vaadin/tests/server/component/grid/RendererTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/grid/RendererTest.java @@ -29,7 +29,6 @@ import com.vaadin.data.Item; import com.vaadin.data.RpcDataProviderExtension; import com.vaadin.data.util.IndexedContainer; import com.vaadin.data.util.converter.Converter; -import com.vaadin.data.util.converter.Converter.ConversionException; import com.vaadin.data.util.converter.StringToIntegerConverter; import com.vaadin.server.VaadinSession; import com.vaadin.tests.util.AlwaysLockedVaadinSession; @@ -176,9 +175,9 @@ public class RendererTest { assertEquals("renderer(2.72)", render(bar, "2.72").asString()); } - @Test(expected = ConversionException.class) + @Test public void testEncodingWithoutConverter() throws Exception { - render(baz, new TestBean()); + assertEquals("", render(baz, new TestBean()).asString()); } @Test diff --git a/uitest/src/com/vaadin/tests/components/grid/GridWithoutRenderer.java b/uitest/src/com/vaadin/tests/components/grid/GridWithoutRenderer.java new file mode 100644 index 0000000000..fd5e6fdc01 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/GridWithoutRenderer.java @@ -0,0 +1,34 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.grid; + +import com.vaadin.annotations.Theme; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.util.PersonContainer; +import com.vaadin.ui.Grid; + +@Theme("valo") +public class GridWithoutRenderer extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Grid grid = new Grid(); + grid.setContainerDataSource(PersonContainer.createWithTestData()); + addComponent(grid); + + } +} diff --git a/uitest/src/com/vaadin/tests/components/grid/GridWithoutRendererTest.java b/uitest/src/com/vaadin/tests/components/grid/GridWithoutRendererTest.java new file mode 100644 index 0000000000..43f5b73357 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/GridWithoutRendererTest.java @@ -0,0 +1,42 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.grid; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.tests.tb3.AbstractTB3Test.RunLocally; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class GridWithoutRendererTest extends SingleBrowserTest { + + @Test + public void ensureNoError() { + openTestURL(); + // WebElement errorIndicator = findElement(By + // .cssSelector("v-error-indicator")); + // System.out.println(errorIndicator); + List<WebElement> errorIndicator = findElements(By + .xpath("//span[@class='v-errorindicator']")); + Assert.assertTrue("There should not be an error indicator", + errorIndicator.isEmpty()); + } + +} |