diff options
author | Leif Åstrand <leif@vaadin.com> | 2012-08-03 16:26:51 +0300 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2012-08-03 16:26:51 +0300 |
commit | 20af2f5623d264a418f73cd9cd053462227d0eb4 (patch) | |
tree | f1bf285158d8e23579667d4c2afcf0704288c756 | |
parent | 94f81dc79526a257451c6638a0696e7505227cb7 (diff) | |
download | vaadin-framework-20af2f5623d264a418f73cd9cd053462227d0eb4.tar.gz vaadin-framework-20af2f5623d264a418f73cd9cd053462227d0eb4.zip |
Support getting translated urls in javascript (#9209)
6 files changed, 97 insertions, 5 deletions
diff --git a/src/com/vaadin/terminal/AbstractJavaScriptExtension.java b/src/com/vaadin/terminal/AbstractJavaScriptExtension.java index ef90d8b23a..df44c3edd5 100644 --- a/src/com/vaadin/terminal/AbstractJavaScriptExtension.java +++ b/src/com/vaadin/terminal/AbstractJavaScriptExtension.java @@ -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> diff --git a/src/com/vaadin/terminal/gwt/client/JavaScriptConnectorHelper.java b/src/com/vaadin/terminal/gwt/client/JavaScriptConnectorHelper.java index 4962bae858..69b8e00603 100644 --- a/src/com/vaadin/terminal/gwt/client/JavaScriptConnectorHelper.java +++ b/src/com/vaadin/terminal/gwt/client/JavaScriptConnectorHelper.java @@ -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); + }), }; }-*/; diff --git a/src/com/vaadin/ui/AbstractJavaScriptComponent.java b/src/com/vaadin/ui/AbstractJavaScriptComponent.java index efcb22dd2b..3668669d16 100644 --- a/src/com/vaadin/ui/AbstractJavaScriptComponent.java +++ b/src/com/vaadin/ui/AbstractJavaScriptComponent.java @@ -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 index 0000000000..16e74aa485 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponent.html @@ -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> diff --git a/tests/testbench/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponent.java b/tests/testbench/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponent.java index 7de2d13663..9ea61b92bb 100644 --- a/tests/testbench/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponent.java +++ b/tests/testbench/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponent.java @@ -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 diff --git a/tests/testbench/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponentConnector.js b/tests/testbench/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponentConnector.js index 4e9c5280b3..fe8367d18a 100644 --- a/tests/testbench/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponentConnector.js +++ b/tests/testbench/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponentConnector.js @@ -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({ |