CRecordWebIncomingJson
The
All JSON messages sent from the browser containing an unknown command in the cmd
field are
forwarded to the targets that have registered interest in the element's ID (field: id
,
see CRecordWebRegisterWidgetOwner).
Messages from the browser always have this format (
{ "cmd ": "onClick2", "id ": "myElementId", "how": "left" }
The message is part of the
The API is located in the plugin NY_
{ "id": "770e679c-26c9-4548-ba41-a5e18759b9b7", "name": "WEB_INCOMING_JSON ", "description": "A json text from the browser.", "slots": [ { "key": "1", "name": "JSON ", "direction": "REQUEST", "mandatory": "true", "type": "STRING", "description": "The json text from the browser. The json must contain a field named 'id'." }, { "key": "2", "name": "ID ", "direction": "REQUEST", "mandatory": "true", "type": "STRING", "description": "The element id." } ] }
Arguments
-
JSON : The JSON text sent by the Javascript from the browser. -
ID : The ID of the html element to which the message belongs.
Usage
Register your target address for this ID.
You need to have the
final CWebApi webApi = new CWebApi(this,// your target mRemote Skin Address); webApi.registerWidgets(new String[]{"myElementId"});
Register a message handler for this message.
// constructor: addMessageHandler(CRecordWebIncomingJson .ID, this::asyncIncomingJson);
Implement the message handler.
private boolean asyncIncomingJson(@NotNull final CEnvelope aEnvelope, @NotNull final CRecord aRecord) throws CException { if (aEnvelope.isAnswer()) { return false; } else { final Stringid =CRecordWebIncomingJson .getId(aRecord, ""); final Stringjson =CRecordWebIncomingJson .getJson(aRecord, "");// ... aEnvelope.setResultSuccess(); return true; } }