Class JsonResponse
java.lang.Object
org.eclipse.scout.rt.ui.html.json.JsonResponse
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected Map<String,
IJsonAdapter<?>> addActionEvent
(String eventTarget, String eventType) addActionEvent
(String eventTarget, String eventType, String eventReference, JSONObject eventData) Same asaddActionEvent(String, String, JSONObject)
but with an 'eventReference' added to the JSON event.addActionEvent
(String eventTarget, String eventType, JSONObject eventData) Note: when converting the response to JSON, events on adapters that are also part of this response are ignored, see alsodoAddEvent(JsonEvent)
void
addAdapter
(IJsonAdapter<?> adapter) Adds an adapter to the response.addPropertyChangeEvent
(String id, String propertyName, Object newValue) protected void
boolean
containsAdapter
(IJsonAdapter<?> adapter) boolean
containsPropertyChangeEvent
(String id, String propertyName) protected boolean
doAddEvent
(JsonEvent event) When we send a new adapter in the JSON response we have to ignore all events for that adapter, since the adapter data already describes the latest state of the adapter.protected boolean
error()
protected int
protected String
void
Causes all registeredIJsonAdapter
s to process their buffered events.The (mutable)startupData
object if the response is marked as "startup response",null
otherwise.boolean
isEmpty()
boolean
boolean
boolean
void
markAsError
(int errorCode, String errorMessage) Marks this JSON response as "error" (default is "success").void
void
registerBufferedEventsAdapter
(IJsonAdapter<?> adapter) Registers the given adapter as a holder of buffered events.void
Removes all traces of the adapter with the given ID from the current response.replaceActionEvent
(String eventTarget, String eventType, JSONObject eventData) Note: when converting the response to JSON, events on adapters that are also part of this response are ignored, see alsodoAddEvent(JsonEvent)
protected JSONObject
toJson()
Returns a JSON string representation of this instance.protected JSONObject
toString()
void
unregisterBufferedEventsAdapter
(IJsonAdapter<?> adapter)
-
Field Details
-
ERR_STARTUP_FAILED
public static final int ERR_STARTUP_FAILED- See Also:
-
ERR_SESSION_TIMEOUT
public static final int ERR_SESSION_TIMEOUT- See Also:
-
ERR_UI_PROCESSING
public static final int ERR_UI_PROCESSING- See Also:
-
ERR_UNSAFE_UPLOAD
public static final int ERR_UNSAFE_UPLOAD- See Also:
-
ERR_REJECTED_UPLOAD
public static final int ERR_REJECTED_UPLOAD- See Also:
-
ERR_VERSION_MISMATCH
public static final int ERR_VERSION_MISMATCH- See Also:
-
PROP_SEQUENCE_NO
- See Also:
-
PROP_COMBINED
- See Also:
-
PROP_EVENTS
- See Also:
-
PROP_ADAPTER_DATA
- See Also:
-
PROP_STARTUP_DATA
- See Also:
-
PROP_ERROR
- See Also:
-
PROP_ERROR_CODE
- See Also:
-
PROP_ERROR_MESSAGE
- See Also:
-
-
Constructor Details
-
JsonResponse
public JsonResponse() -
JsonResponse
-
-
Method Details
-
getSequenceNo
-
addAdapter
Adds an adapter to the response. All adapters stored on the response are transferred to the client (browser) as JSON object. Only new adapters must be transferred, adapters already transferred to the client can be solely referenced by their ID.Note that in javascript the adapters are not created unless the first event is received.
-
addPropertyChangeEvent
- Parameters:
id
- Adapter IDpropertyName
- property namenewValue
- property value
-
addActionEvent
-
addActionEvent
Note: when converting the response to JSON, events on adapters that are also part of this response are ignored, see alsodoAddEvent(JsonEvent)
-
addActionEvent
public JsonEvent addActionEvent(String eventTarget, String eventType, String eventReference, JSONObject eventData) Same asaddActionEvent(String, String, JSONObject)
but with an 'eventReference' added to the JSON event. This reference is considered additionally to 'eventTarget' when removing events (seeremoveJsonAdapter(String)
).Note: when converting the response to JSON, events on adapters that are also part of this response are ignored, see also
doAddEvent(JsonEvent)
-
replaceActionEvent
Note: when converting the response to JSON, events on adapters that are also part of this response are ignored, see alsodoAddEvent(JsonEvent)
-
containsAdapter
-
containsPropertyChangeEvent
-
registerBufferedEventsAdapter
Registers the given adapter as a holder of buffered events. Before executingtoJson()
those buffers are consumed automatically. (Additionally, all registered buffers can be consumed manually withfireProcessBufferedEvents()
.) -
unregisterBufferedEventsAdapter
-
markAsStartupResponse
public void markAsStartupResponse() -
isMarkedAsStartupResponse
public boolean isMarkedAsStartupResponse() -
getStartupData
The (mutable)startupData
object if the response is marked as "startup response",null
otherwise. -
markAsError
Marks this JSON response as "error" (default is "success").- Parameters:
errorCode
- An arbitrary number indicating the type of error.errorMessage
- A message describing the error. This message is mostly useful for debugging purposes. Usually, it is not shown to the user, because it is not language-dependent. If possible, the displayed message is translated by the client using theerrorCode
parameter (see Session.js).
-
isMarkedAsError
public boolean isMarkedAsError() -
isWritable
public boolean isWritable()- Returns:
true
if this response is still writable (e.g. new adapters and events can be added). AftertoJson()
was called and the resulting JSON was sent to the UI, this method will returnfalse
forever.
-
assertWritable
protected void assertWritable() -
toJson
Returns a JSON string representation of this instance. This method is typically called at the end of a request.Attention: This method is not free of side effects!
- Buffered events are processed. This may lead to the addition of new adapters and events (see implementations of
IJsonAdapter.processBufferedEvents()
). - After that, the request will not be writable anymore! Any attempt to alter the response afterwards
results in an
Assertions.AssertionException
to be thrown.isWritable()
will always returnsfalse
.
"adapterData"
property. All events are transferred in the"events"
property. An ascending sequence number is put in the"#"
property. This method will call thetoJson()
method on all adapter objects. Note that you can NOT create new adapter instances when the toJson() method runs! All new adapter instances must be created before: either in theattachModel()
method or in an event handler method likehandleXYZ()
. The technical reason for this is, first: new adapters are added to the current response (see UiSession), but at the point in time toJson() is called, we already have a new instance of the current response. Second: when we loop through the adapterMap and call toJson() for each adapter, if the adapter would create another adapter in its toJson() method, the adapterMap would grow, which would cause a ConcurrentModificationException. Additionally we should conceptually separate object creation from JSON output creation. - Buffered events are processed. This may lead to the addition of new adapters and events (see implementations of
-
toJsonInternal
-
fireProcessBufferedEvents
public void fireProcessBufferedEvents()Causes all registeredIJsonAdapter
s to process their buffered events. This may add some events and adapters to this response. This method is called automatically duringtoJson()
. -
doAddEvent
When we send a new adapter in the JSON response we have to ignore all events for that adapter, since the adapter data already describes the latest state of the adapter.For property change events this is just an optimization to reduce the response size.
For other event types it may be crucial that the events are not sent.
Example: NodesInserted event on tree must not be sent since the same nodes are already sent by Tree.toJson. -
removeJsonAdapter
Removes all traces of the adapter with the given ID from the current response. This includes all events with the given ID as target or "reference". Also, if the adapter was registered as "buffered events adapter", it is unregistered automatically. Any deferred model event for this adapter will therefore not be handled.- Parameters:
id
- Adapter ID to be removed
-
getEventList
- Returns:
- a copy of the event list
-
eventList
-
adapterMap
-
startupData
-
error
protected boolean error() -
errorCode
protected int errorCode() -
errorMessage
-
isEmpty
public boolean isEmpty() -
toString
-