import com.vaadin.terminal.gwt.client.communication.MethodInvocation;
import com.vaadin.terminal.gwt.client.communication.RpcManager;
import com.vaadin.terminal.gwt.client.communication.SerializerMap;
-import com.vaadin.terminal.gwt.client.communication.SharedState;
import com.vaadin.terminal.gwt.client.communication.StateChangeEvent;
import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector;
import com.vaadin.terminal.gwt.client.ui.VContextMenu;
invocationJson.set(2,
new JSONString(invocation.getMethodName()));
JSONArray paramJson = new JSONArray();
+ boolean restrictToInternalTypes = isLegacyVariableChange(invocation);
for (int i = 0; i < invocation.getParameters().length; ++i) {
// TODO non-static encoder? type registration?
paramJson.set(i, JsonEncoder.encode(
- invocation.getParameters()[i], getConnectorMap(),
- this));
+ invocation.getParameters()[i],
+ restrictToInternalTypes, getConnectorMap(), this));
}
invocationJson.set(3, paramJson);
reqJson.set(reqJson.size(), invocationJson);
makeUidlRequest(req.toString(), extraParams, forceSync);
}
+ private boolean isLegacyVariableChange(MethodInvocation invocation) {
+ return ApplicationConnection.UPDATE_VARIABLE_METHOD.equals(invocation
+ .getInterfaceName())
+ && ApplicationConnection.UPDATE_VARIABLE_METHOD
+ .equals(invocation.getMethodName());
+ }
+
/**
* Sends a new value for the given paintables given variable to the server.
* <p>
* @param connection
* @return JSON representation of the value
*/
- public static JSONValue encode(Object value, ConnectorMap connectorMap,
+ public static JSONValue encode(Object value,
+ boolean restrictToInternalTypes, ConnectorMap connectorMap,
ApplicationConnection connection) {
if (null == value) {
return combineTypeAndValue(VTYPE_NULL, JSONNull.getInstance());
return combineTypeAndValue(VTYPE_BOOLEAN,
JSONBoolean.getInstance((Boolean) value));
} else if (value instanceof Object[]) {
- return encodeObjectArray((Object[]) value, connectorMap, connection);
+ return encodeObjectArray((Object[]) value, restrictToInternalTypes,
+ connectorMap, connection);
} else if (value instanceof Enum) {
- Enum e = (Enum) value;
- return encodeEnum(e, connectorMap, connection);
+ if (restrictToInternalTypes) {
+ // Enums are encoded as strings in Vaadin 6 so we still do that
+ // for backwards copmatibility.
+ return encode(value.toString(), restrictToInternalTypes,
+ connectorMap, connection);
+ } else {
+ Enum e = (Enum) value;
+ return encodeEnum(e, connectorMap, connection);
+ }
} else if (value instanceof Map) {
Map<Object, Object> map = (Map<Object, Object>) value;
JSONObject jsonMap = new JSONObject();
+ " Failed map used "
+ mapKey.getClass().getName() + " as keys");
}
- jsonMap.put((String) mapKey,
- encode(mapValue, connectorMap, connection));
+ jsonMap.put(
+ (String) mapKey,
+ encode(mapValue, restrictToInternalTypes, connectorMap,
+ connection));
}
return combineTypeAndValue(type, jsonMap);
} else if (value instanceof Connector) {
return combineTypeAndValue(VTYPE_CONNECTOR, new JSONString(
connector.getConnectorId()));
} else if (value instanceof Collection) {
- return encodeCollection((Collection) value, connectorMap,
- connection);
+ return encodeCollection((Collection) value,
+ restrictToInternalTypes, connectorMap, connection);
} else {
String transportType = getTransportType(value);
if (transportType != null) {
}
private static JSONValue encodeObjectArray(Object[] array,
- ConnectorMap connectorMap, ApplicationConnection connection) {
+ boolean restrictToInternalTypes, ConnectorMap connectorMap,
+ ApplicationConnection connection) {
JSONArray jsonArray = new JSONArray();
for (int i = 0; i < array.length; ++i) {
// TODO handle object graph loops?
- jsonArray.set(i, encode(array[i], connectorMap, connection));
+ jsonArray.set(
+ i,
+ encode(array[i], restrictToInternalTypes, connectorMap,
+ connection));
}
return combineTypeAndValue(VTYPE_ARRAY, jsonArray);
}
private static JSONValue encodeCollection(Collection collection,
- ConnectorMap connectorMap, ApplicationConnection connection) {
+ boolean restrictToInternalTypes, ConnectorMap connectorMap,
+ ApplicationConnection connection) {
JSONArray jsonArray = new JSONArray();
int idx = 0;
for (Object o : collection) {
- JSONValue encodedObject = encode(o, connectorMap, connection);
+ JSONValue encodedObject = encode(o, restrictToInternalTypes,
+ connectorMap, connection);
jsonArray.set(idx++, encodedObject);
}
if (collection instanceof Set) {