import com.vaadin.terminal.gwt.client.communication.RpcManager;
import com.vaadin.terminal.gwt.client.communication.SerializerMap;
import com.vaadin.terminal.gwt.client.communication.StateChangeEvent;
+import com.vaadin.terminal.gwt.client.communication.UidlValue;
import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector;
import com.vaadin.terminal.gwt.client.ui.VContextMenu;
import com.vaadin.terminal.gwt.client.ui.dd.VDragAndDropManager;
// TODO could eliminate invocations of same shared variable setter
addMethodInvocationToQueue(new MethodInvocation(connectorId,
UPDATE_VARIABLE_INTERFACE, UPDATE_VARIABLE_METHOD,
- new Object[] { variableName, value }), immediate);
+ new Object[] { variableName, new UidlValue(value) }), immediate);
}
/**
public static final String VTYPE_SET = "q";
public static final String VTYPE_NULL = "n";
+ /**
+ * Temporary hack to get variable changes decoded as internal types in
+ * JsonCodec.
+ */
+ public static final String VTYPE_UIDL_VALUE = "v";
+
/**
* Encode a value to a JSON representation for transport from the client to
* the server.
} else if (value instanceof Collection) {
return encodeCollection((Collection) value,
restrictToInternalTypes, connectorMap, connection);
+ } else if (value instanceof UidlValue) {
+ return encodeVariableChange((UidlValue) value, connectorMap,
+ connection);
} else {
String transportType = getTransportType(value);
if (transportType != null) {
}
}
+ private static JSONValue encodeVariableChange(UidlValue value,
+ ConnectorMap connectorMap, ApplicationConnection connection) {
+ JSONArray encodedValue = encode(value.getValue(), true, connectorMap,
+ connection).isArray();
+
+ return combineTypeAndValue(VTYPE_UIDL_VALUE, encodedValue);
+ }
+
private static JSONValue encodeMap(Map<Object, Object> map,
boolean restrictToInternalTypes, ConnectorMap connectorMap,
ApplicationConnection connection) {
--- /dev/null
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.terminal.gwt.client.communication;
+
+import java.io.Serializable;
+
+public class UidlValue implements Serializable {
+ private Object value;
+
+ public UidlValue(Object value) {
+ this.value = value;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ return "" + value;
+ }
+
+}
import com.vaadin.terminal.gwt.client.Connector;
import com.vaadin.terminal.gwt.client.communication.MethodInvocation;
import com.vaadin.terminal.gwt.client.communication.SharedState;
+import com.vaadin.terminal.gwt.client.communication.UidlValue;
import com.vaadin.terminal.gwt.server.BootstrapHandler.BootstrapContext;
import com.vaadin.terminal.gwt.server.ComponentSizeValidator.InvalidLayout;
import com.vaadin.ui.AbstractComponent;
String variableName = (String) JsonCodec
.decodeInternalType(String.class, true,
parametersJson.getJSONArray(0), application);
- Object value = JsonCodec.decodeInternalType(
+ UidlValue uidlValue = (UidlValue) JsonCodec.decodeInternalType(
parametersJson.getJSONArray(1), application);
+ Object value = uidlValue.getValue();
+
if (previousInvocation != null
&& previousInvocation.getConnectorId().equals(connectorId)) {
previousInvocation.setVariableChange(variableName, value);
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import com.vaadin.external.json.JSONObject;
import com.vaadin.terminal.gwt.client.Connector;
import com.vaadin.terminal.gwt.client.communication.JsonEncoder;
+import com.vaadin.terminal.gwt.client.communication.UidlValue;
import com.vaadin.ui.Component;
/**
registerType(HashMap.class, JsonEncoder.VTYPE_MAP);
registerType(List.class, JsonEncoder.VTYPE_LIST);
registerType(Set.class, JsonEncoder.VTYPE_SET);
+ registerType(UidlValue.class, JsonEncoder.VTYPE_UIDL_VALUE);
}
private static void registerType(Class<?> type, String transportType) {
if (JsonEncoder.VTYPE_NULL.equals(encodedTransportType)) {
return null;
}
+
+ // VariableChange
+ if (JsonEncoder.VTYPE_UIDL_VALUE.contentEquals(transportType)) {
+ return decodeVariableChange((JSONArray) encodedJsonValue,
+ application);
+ }
+
// Collections
if (JsonEncoder.VTYPE_LIST.equals(transportType)) {
return decodeList(targetType, restrictToInternalTypes,
throw new JSONException("Unknown type " + transportType);
}
+ private static UidlValue decodeVariableChange(JSONArray encodedJsonValue,
+ Application application) throws JSONException {
+ String type = encodedJsonValue.getString(0);
+
+ // Fake format used by decode method
+ JSONArray valueAndType = new JSONArray(Arrays.asList(type,
+ encodedJsonValue.get(1)));
+ Object decodedValue = decodeInternalType(valueAndType, application);
+ return new UidlValue(decodedValue);
+ }
+
private static boolean transportTypesCompatible(
String encodedTransportType, String transportType) {
if (encodedTransportType == null) {