]> source.dussan.org Git - vaadin-framework.git/commitdiff
Support getting translated urls in javascript (#9209)
authorLeif Åstrand <leif@vaadin.com>
Fri, 3 Aug 2012 13:26:51 +0000 (16:26 +0300)
committerLeif Åstrand <leif@vaadin.com>
Fri, 3 Aug 2012 13:26:51 +0000 (16:26 +0300)
src/com/vaadin/terminal/AbstractJavaScriptExtension.java
src/com/vaadin/terminal/gwt/client/JavaScriptConnectorHelper.java
src/com/vaadin/ui/AbstractJavaScriptComponent.java
tests/testbench/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponent.html [new file with mode: 0644]
tests/testbench/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponent.java
tests/testbench/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponentConnector.js

index ef90d8b23a768e24f3f87452c71a733d98f2f8e0..df44c3edd548e2dfdd424e2ac4a2ef697e8bef29 100644 (file)
@@ -5,6 +5,7 @@
 package com.vaadin.terminal;
 
 import com.vaadin.shared.JavaScriptExtensionState;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
 import com.vaadin.ui.JavaScriptCallback;
 
 /**
@@ -63,6 +64,9 @@ import com.vaadin.ui.JavaScriptCallback;
  * exception when called. The scheme for conversion between Java types in the
  * RPC interface and the JavaScript values that should be passed to the
  * functions is described bellow.</li>
+ * <li><code>translateVaadinUri(uri)</code> - Translates a Vaadin URI to a URL
+ * that can be used in the browser. This is just way of accessing
+ * {@link ApplicationConnection#translateVaadinUri(String)}</li>
  * </ul>
  * The connector wrapper also supports these special functions:
  * <ul>
index 4962bae858e4a4d08cc862c5d8302d12973b2766..69b8e006039b9678b294e2c52a545d480da631dc 100644 (file)
@@ -145,8 +145,9 @@ public class JavaScriptConnectorHelper {
 
     private JavaScriptObject getConnectorWrapper() {
         if (connectorWrapper == null) {
-            connectorWrapper = createConnectorWrapper(this, nativeState,
-                    rpcMap, connector.getConnectorId(), rpcObjects);
+            connectorWrapper = createConnectorWrapper(this,
+                    connector.getConnection(), nativeState, rpcMap,
+                    connector.getConnectorId(), rpcObjects);
         }
 
         return connectorWrapper;
@@ -161,9 +162,9 @@ public class JavaScriptConnectorHelper {
     }-*/;
 
     private static native JavaScriptObject createConnectorWrapper(
-            JavaScriptConnectorHelper h, JavaScriptObject nativeState,
-            JavaScriptObject registeredRpc, String connectorId,
-            Map<String, JavaScriptObject> rpcObjects)
+            JavaScriptConnectorHelper h, ApplicationConnection c,
+            JavaScriptObject nativeState, JavaScriptObject registeredRpc,
+            String connectorId, Map<String, JavaScriptObject> rpcObjects)
     /*-{
         return {
             'getConnectorId': function() {
@@ -195,6 +196,9 @@ public class JavaScriptConnectorHelper {
                 }
                 registeredRpc[iface].push(rpcHandler);
             },
+            'translateVaadinUri': $entry(function(uri) {
+                return c.@com.vaadin.terminal.gwt.client.ApplicationConnection::translateVaadinUri(Ljava/lang/String;)(uri);
+            }),
         };
     }-*/;
 
index efcb22dd2b49f6e78c02ecd81f97d1289985ebd9..3668669d1615225eb34eda72173843c186c98645 100644 (file)
@@ -5,6 +5,7 @@ package com.vaadin.ui;
 
 import com.vaadin.shared.ui.JavaScriptComponentState;
 import com.vaadin.terminal.JavaScriptCallbackHelper;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
 import com.vaadin.terminal.gwt.client.ui.JavaScriptWidget;
 
 /**
@@ -66,6 +67,9 @@ import com.vaadin.terminal.gwt.client.ui.JavaScriptWidget;
  * exception when called. The scheme for conversion between Java types in the
  * RPC interface and the JavaScript values that should be passed to the
  * functions is described bellow.</li>
+ * <li><code>translateVaadinUri(uri)</code> - Translates a Vaadin URI to a URL
+ * that can be used in the browser. This is just way of accessing
+ * {@link ApplicationConnection#translateVaadinUri(String)}</li>
  * </ul>
  * The connector wrapper also supports these special functions:
  * <ul>
diff --git a/tests/testbench/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponent.html b/tests/testbench/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponent.html
new file mode 100644 (file)
index 0000000..16e74aa
--- /dev/null
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>New Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/run/com.vaadin.tests.components.javascriptcomponent.BasicJavaScriptComponent?restartApplication</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsjavascriptcomponentBasicJavaScriptComponent::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[0]</td>
+       <td>3. Got callback message: Callback message processed</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsjavascriptcomponentBasicJavaScriptComponent::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[1]</td>
+       <td>2. Got RPC message: RPC message processed</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsjavascriptcomponentBasicJavaScriptComponent::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[2]</td>
+       <td>1. Parent ids checked</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsjavascriptcomponentBasicJavaScriptComponent::/VVerticalLayout[0]/VVerticalLayout[0]/domChild[1]/domChild[0]/domChild[0]</td>
+       <td>Component caption</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsjavascriptcomponentBasicJavaScriptComponent::/VVerticalLayout[0]/VVerticalLayout[0]/JavaScriptWidget[0]/domChild[0]</td>
+       <td>4. Url: /run/com.vaadin.tests.components.javascriptcomponent.BasicJavaScriptComponent/APP/1/test</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsjavascriptcomponentBasicJavaScriptComponent::/VVerticalLayout[0]/VVerticalLayout[0]/JavaScriptWidget[0]/domChild[1]</td>
+       <td>3. State message: Second state message</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsjavascriptcomponentBasicJavaScriptComponent::/VVerticalLayout[0]/VVerticalLayout[0]/JavaScriptWidget[0]/domChild[2]</td>
+       <td>2. State message: First state message</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsjavascriptcomponentBasicJavaScriptComponent::/VVerticalLayout[0]/VVerticalLayout[0]/JavaScriptWidget[0]/domChild[3]</td>
+       <td>1. Parent element className: v-verticallayout v-connector v-has-width</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
index 7de2d1366321f42129752fe2087a8004fab2f0e5..9ea61b92bb6d7fe76f2c2087fa5e789781265e55 100644 (file)
@@ -12,8 +12,11 @@ import com.vaadin.external.json.JSONArray;
 import com.vaadin.external.json.JSONException;
 import com.vaadin.shared.communication.ClientRpc;
 import com.vaadin.shared.communication.ServerRpc;
+import com.vaadin.shared.communication.URLReference;
 import com.vaadin.shared.ui.JavaScriptComponentState;
+import com.vaadin.terminal.ClassResource;
 import com.vaadin.terminal.WrappedRequest;
+import com.vaadin.terminal.gwt.server.ResourceReference;
 import com.vaadin.tests.components.AbstractTestRoot;
 import com.vaadin.tests.util.Log;
 import com.vaadin.ui.AbstractJavaScriptComponent;
@@ -28,6 +31,7 @@ public class BasicJavaScriptComponent extends AbstractTestRoot {
 
     public static class TestState extends JavaScriptComponentState {
         private List<String> messages = new ArrayList<String>();
+        private URLReference url;
 
         public List<String> getMessages() {
             return messages;
@@ -36,6 +40,14 @@ public class BasicJavaScriptComponent extends AbstractTestRoot {
         public void setMessages(List<String> messages) {
             this.messages = messages;
         }
+
+        public URLReference getUrl() {
+            return url;
+        }
+
+        public void setUrl(URLReference url) {
+            this.url = url;
+        }
     }
 
     @JavaScript("BasicJavaScriptComponentConnector.js")
@@ -83,6 +95,9 @@ public class BasicJavaScriptComponent extends AbstractTestRoot {
                     .setMessages(
                             Arrays.asList("First state message",
                                     "Second state message"));
+            ClassResource resource = new ClassResource("test",
+                    BasicJavaScriptComponent.this.getApplication());
+            getState().setUrl(new ResourceReference(resource));
         }
 
         @Override
index 4e9c5280b32e17e3d74c3c6f98955ce672b1ff1b..fe8367d18a40cb2b5622e73b024b8ca03ba25495 100644 (file)
@@ -23,6 +23,9 @@ window.com_vaadin_tests_components_javascriptcomponent_BasicJavaScriptComponent_
                for(var i = 0; i < messages.length; i++) {
                        log("State message: " + messages[i]);
                }
+               
+               var url = this.getState().url;
+               log("Url: " + this.translateVaadinUri(url.uRL)); //Strange format, see #9210
        }
        
        this.registerRpc({