summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>2017-05-03 11:57:03 +0300
committerHenri Sara <henri.sara@gmail.com>2017-05-03 11:57:03 +0300
commitff52c42738a96c3fde01c40d33075376bcae1339 (patch)
tree77262dd6f028fca86232dedd611a8fcfe262d872 /client
parentb60ab78e7ca9ed232eac2388c3a9ca6e1af423af (diff)
downloadvaadin-framework-ff52c42738a96c3fde01c40d33075376bcae1339.tar.gz
vaadin-framework-ff52c42738a96c3fde01c40d33075376bcae1339.zip
Fix ComponentLocator with inherited classes without custom connector (#9176)
Logic for finding elements corresponding a server-side classname does not work with inherited classes. For example making MyGrid extends Grid, you could not find the specific MyGrid, but only the common Grid. In most cases this is not a problem since these components are usually the only instance of said superclass, but the Composite introduced in the same UI, which makes testing them impossible. This patch adds the specific classname information for ServerConnectors that can be used to find the correct connector instance.
Diffstat (limited to 'client')
-rw-r--r--client/src/main/java/com/vaadin/client/JavaScriptConnectorHelper.java7
-rw-r--r--client/src/main/java/com/vaadin/client/ServerConnector.java35
-rw-r--r--client/src/main/java/com/vaadin/client/WidgetSet.java6
-rw-r--r--client/src/main/java/com/vaadin/client/componentlocator/VaadinFinderLocatorStrategy.java7
-rw-r--r--client/src/main/java/com/vaadin/client/ui/AbstractConnector.java11
5 files changed, 54 insertions, 12 deletions
diff --git a/client/src/main/java/com/vaadin/client/JavaScriptConnectorHelper.java b/client/src/main/java/com/vaadin/client/JavaScriptConnectorHelper.java
index 7f4b1b6759..81793084d2 100644
--- a/client/src/main/java/com/vaadin/client/JavaScriptConnectorHelper.java
+++ b/client/src/main/java/com/vaadin/client/JavaScriptConnectorHelper.java
@@ -50,7 +50,6 @@ public class JavaScriptConnectorHelper {
private final Map<Element, Map<JavaScriptObject, ElementResizeListener>> resizeListeners = new HashMap<>();
private JavaScriptObject connectorWrapper;
- private int tag;
private String initFunctionName;
private String tagName;
@@ -407,10 +406,6 @@ public class JavaScriptConnectorHelper {
return new Object[] { Util.json2jso(parametersJson) };
}
- public void setTag(int tag) {
- this.tag = tag;
- }
-
public void invokeJsRpc(MethodInvocation invocation,
JsonArray parametersJson) {
String iface = invocation.getInterfaceName();
@@ -496,7 +491,7 @@ public class JavaScriptConnectorHelper {
ApplicationConfiguration conf = connector.getConnection()
.getConfiguration();
ArrayList<String> initFunctionNames = new ArrayList<String>();
- Integer tag = Integer.valueOf(this.tag);
+ Integer tag = Integer.valueOf(connector.getTag());
while (tag != null) {
String initFunctionName = conf.getServerSideClassNameForTag(tag);
initFunctionName = initFunctionName.replaceAll("\\.", "_");
diff --git a/client/src/main/java/com/vaadin/client/ServerConnector.java b/client/src/main/java/com/vaadin/client/ServerConnector.java
index 9ab076305c..71d65732bb 100644
--- a/client/src/main/java/com/vaadin/client/ServerConnector.java
+++ b/client/src/main/java/com/vaadin/client/ServerConnector.java
@@ -217,4 +217,39 @@ public interface ServerConnector extends Connector {
*/
public boolean hasEventListener(String eventIdentifier);
+ /**
+ * Sets the connector type tag for this connector. This should only be
+ * called from
+ * {@link WidgetSet#createConnector(int, ApplicationConfiguration)}
+ *
+ * @see #getTag()
+ *
+ * @param tag
+ * the connector type tag
+ *
+ * @deprecated This is an internal method and should not be called by an
+ * application developer.
+ *
+ * @since 8.1
+ */
+ @Deprecated
+ public void setTag(int tag);
+
+ /**
+ * Gets the connector type tag for this connector. This type tag is an
+ * identifier used to map client-side connectors to their server-side
+ * classes. The server-side class information is stored in
+ * {@link ApplicationConfiguration} and contains class names and their
+ * hierarchy.
+ *
+ * @see ApplicationConfiguration#getServerSideClassNameForTag(Integer)
+ * @see ApplicationConfiguration#getTagsForServerSideClassName(String)
+ * @see ApplicationConfiguration#getParentTag(int)
+ *
+ * @return the connector type tag
+ *
+ * @since 8.1
+ */
+ public int getTag();
+
}
diff --git a/client/src/main/java/com/vaadin/client/WidgetSet.java b/client/src/main/java/com/vaadin/client/WidgetSet.java
index cf3db7aaa9..2fc486b00e 100644
--- a/client/src/main/java/com/vaadin/client/WidgetSet.java
+++ b/client/src/main/java/com/vaadin/client/WidgetSet.java
@@ -20,7 +20,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import com.google.gwt.core.client.GWT;
-import com.vaadin.client.communication.HasJavaScriptConnectorHelper;
import com.vaadin.client.metadata.BundleLoadCallback;
import com.vaadin.client.metadata.ConnectorBundleLoader;
import com.vaadin.client.metadata.NoDataException;
@@ -80,10 +79,7 @@ public class WidgetSet {
*/
ServerConnector connector = (ServerConnector) TypeData
.getType(classType).createInstance();
- if (connector instanceof HasJavaScriptConnectorHelper) {
- ((HasJavaScriptConnectorHelper) connector)
- .getJavascriptConnectorHelper().setTag(tag);
- }
+ connector.setTag(tag);
return connector;
}
} catch (NoDataException e) {
diff --git a/client/src/main/java/com/vaadin/client/componentlocator/VaadinFinderLocatorStrategy.java b/client/src/main/java/com/vaadin/client/componentlocator/VaadinFinderLocatorStrategy.java
index 3f46a0a812..c7abe8c15f 100644
--- a/client/src/main/java/com/vaadin/client/componentlocator/VaadinFinderLocatorStrategy.java
+++ b/client/src/main/java/com/vaadin/client/componentlocator/VaadinFinderLocatorStrategy.java
@@ -608,12 +608,17 @@ public class VaadinFinderLocatorStrategy implements LocatorStrategy {
String widgetName) {
List<String> ids = getIDsForConnector(connector);
+ String exactClass = connector.getConnection().getConfiguration()
+ .getServerSideClassNameForTag(connector.getTag());
+ if (!ids.contains(exactClass)) {
+ ids.add(exactClass);
+ }
List<Integer> widgetTags = new ArrayList<>();
widgetTags.addAll(getTags(widgetName));
if (widgetTags.size() == 0) {
- widgetTags.addAll(getTags("com.vaadin.ui" + widgetName));
+ widgetTags.addAll(getTags("com.vaadin.ui." + widgetName));
}
for (int i = 0, l = ids.size(); i < l; ++i) {
diff --git a/client/src/main/java/com/vaadin/client/ui/AbstractConnector.java b/client/src/main/java/com/vaadin/client/ui/AbstractConnector.java
index 93ab05a883..f7bdf80ee0 100644
--- a/client/src/main/java/com/vaadin/client/ui/AbstractConnector.java
+++ b/client/src/main/java/com/vaadin/client/ui/AbstractConnector.java
@@ -61,6 +61,7 @@ public abstract class AbstractConnector
private ApplicationConnection connection;
private String id;
+ private int tag;
private HandlerManager handlerManager;
private FastStringMap<HandlerManager> statePropertyHandlerManagers;
@@ -523,4 +524,14 @@ public abstract class AbstractConnector
}
}
+
+ @Override
+ public int getTag() {
+ return tag;
+ }
+
+ @Override
+ public void setTag(int tag) {
+ this.tag = tag;
+ }
}