summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2016-01-16 13:11:22 +0200
committerelmot <elmot@vaadin.com>2016-01-21 17:12:19 +0200
commit955eab89c0fe5aba7606fea336077b39bd09371f (patch)
tree31b84375280e1a0f449a817fb1e2b69c7a7e99c7
parent79372666205a0fe799d3233f250faccdf7096d5d (diff)
downloadvaadin-framework-955eab89c0fe5aba7606fea336077b39bd09371f.tar.gz
vaadin-framework-955eab89c0fe5aba7606fea336077b39bd09371f.zip
Allow legacy components to paint infinity double values again (#19447)
JsonPaintTarget.addAttribute(String,double) converts infinity values to { "name": Infinity }. This is not valid JSON but has "always worked" and at least NumberField relies on being able to send infinity values. For state and RPC it's not possible to send 'infinity' as JsonNumber converts those to null. It is not possible to send 'infinity' back to the server using a legacy variable either as also in this case JsonNumber is used and the value becomes null. This fix should be reverted when legacy variable support is removed. Change-Id: I19d17368f9da97a81fc9f780749dc4f0a8d3ee9b
-rw-r--r--client/src/com/vaadin/client/communication/MessageHandler.java6
-rw-r--r--uitest/src/com/vaadin/tests/serialization/LegacySerializerUI.java51
-rw-r--r--uitest/src/com/vaadin/tests/serialization/LegacySerializerUITest.java36
-rw-r--r--uitest/src/com/vaadin/tests/widgetset/client/LegacySerializerConnector.java42
4 files changed, 134 insertions, 1 deletions
diff --git a/client/src/com/vaadin/client/communication/MessageHandler.java b/client/src/com/vaadin/client/communication/MessageHandler.java
index 96f9992b6e..3ffadeb9ce 100644
--- a/client/src/com/vaadin/client/communication/MessageHandler.java
+++ b/client/src/com/vaadin/client/communication/MessageHandler.java
@@ -1784,7 +1784,11 @@ public class MessageHandler {
private static native ValueMap parseJSONResponse(String jsonText)
/*-{
- return JSON.parse(jsonText);
+ try {
+ return JSON.parse(jsonText);
+ } catch (ignored) {
+ return eval('(' + jsonText + ')');
+ }
}-*/;
/**
diff --git a/uitest/src/com/vaadin/tests/serialization/LegacySerializerUI.java b/uitest/src/com/vaadin/tests/serialization/LegacySerializerUI.java
new file mode 100644
index 0000000000..618462b203
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/serialization/LegacySerializerUI.java
@@ -0,0 +1,51 @@
+/*
+ * 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.serialization;
+
+import java.util.Map;
+
+import com.vaadin.annotations.Widgetset;
+import com.vaadin.server.PaintException;
+import com.vaadin.server.PaintTarget;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.ui.AbstractComponent;
+import com.vaadin.ui.LegacyComponent;
+
+@Widgetset("com.vaadin.tests.widgetset.TestingWidgetSet")
+public class LegacySerializerUI extends AbstractTestUIWithLog {
+
+ public class LegacySerializerComponent extends AbstractComponent implements
+ LegacyComponent {
+
+ @Override
+ public void changeVariables(Object source, Map<String, Object> variables) {
+ log("doubleInfinity: " + variables.get("doubleInfinity"));
+ }
+
+ @Override
+ public void paintContent(PaintTarget target) throws PaintException {
+ target.addAttribute("doubleInfinity", Double.POSITIVE_INFINITY);
+ }
+
+ }
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ addComponent(new LegacySerializerComponent());
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/serialization/LegacySerializerUITest.java b/uitest/src/com/vaadin/tests/serialization/LegacySerializerUITest.java
new file mode 100644
index 0000000000..f3a5561e40
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/serialization/LegacySerializerUITest.java
@@ -0,0 +1,36 @@
+/*
+ * 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.serialization;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class LegacySerializerUITest extends SingleBrowserTest {
+
+ @Test
+ public void testInfinity() {
+ openTestURL();
+ WebElement html = findElement(By.className("gwt-HTML"));
+ Assert.assertEquals("doubleInfinity: Infinity", html.getText());
+ // Can't send infinity back, never have been able to
+ Assert.assertEquals("1. doubleInfinity: null", getLogRow(0));
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/widgetset/client/LegacySerializerConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/LegacySerializerConnector.java
new file mode 100644
index 0000000000..9c261b9505
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/widgetset/client/LegacySerializerConnector.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.widgetset.client;
+
+import com.google.gwt.user.client.ui.HTML;
+import com.vaadin.client.ApplicationConnection;
+import com.vaadin.client.Paintable;
+import com.vaadin.client.UIDL;
+import com.vaadin.client.ui.AbstractComponentConnector;
+import com.vaadin.shared.ui.Connect;
+import com.vaadin.tests.serialization.LegacySerializerUI.LegacySerializerComponent;
+
+@Connect(value = LegacySerializerComponent.class)
+public class LegacySerializerConnector extends AbstractComponentConnector
+ implements Paintable {
+
+ @Override
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ double doubleAttribute = uidl.getDoubleAttribute("doubleInfinity");
+ getWidget().setHTML("doubleInfinity: " + doubleAttribute);
+ client.updateVariable(getConnectorId(), "doubleInfinity",
+ doubleAttribute, true);
+ }
+
+ @Override
+ public HTML getWidget() {
+ return (HTML) super.getWidget();
+ }
+}