Af2SharedObject.data - affluxis/csjava GitHub Wiki
Usage
myRemoteSharedObject.data
Description
Read-only property; the collection of attributes assigned to the data property of the object; these attributes can be shared and/or stored. Each attribute can be an object of any of the basic Java types — Array, Number, Boolean, and so on. For example, the following lines assign values to various aspects of a shared object:
itemsArray = new int[3];
itemsArray[0] = 101;
itemsArray[1] = 346;
itemsArray[2] = 483;
currentUserIsAdmin = true;
currentUserName = "Ramona";
so.setProperty("itemNumbers", itemsArray);
so.setProperty("adminPrivileges", currentUserIsAdmin);
so.setProperty("userName", currentUserName);
All attributes of a shared object’s data property are available to all clients connected to the shared object, and all of them are saved if the object is persistent. If you assign null to the attribute of a remote shared object, the server deletes the attribute, and Af2SharedObject.onSync is invoked with a code property of delete.
Example
The following example sets the current stream to the user’s selection.
Gson gs = new Gson();
JsonParser jp = new JsonParser();
LinkedTreeMap pl = (LinkedTreeMap) so.data.get("msgList");
JsonObject jo = gs.toJsonTree(pl).getAsJsonObject();
JsonElement je = jp.parse(jo.toString());
Param param = gs.fromJson(je, Param.class);
curStream = param.streamName;
See also
Af2SharedObject.onSync, Af2SharedObject.setProperty