use of com.servoy.j2db.server.ngclient.property.ComponentPropertyType.IModelWriter in project servoy-client by Servoy.
the class ComponentTypeSabloValue method fullToJSON.
/**
* Writes the entire value of this property as JSON. This includes the template values, not just the runtime component properties.
* This is currently needed and can get called if the property is nested inside other complex properties (json object/array) that sometimes
* might want/need to send again the entire content.
*/
public JSONWriter fullToJSON(final JSONWriter writer, DataConversion conversionMarkers, ComponentPropertyType componentPropertyType) throws JSONException {
// so that the client knows it must use the custom client side JS for what JSON it gets
if (conversionMarkers != null)
conversionMarkers.convert(ComponentPropertyType.TYPE_NAME);
// create children of component as specified by this property
final FormElement fe = formElementValue.element;
writer.object();
// get template model values
final TypedData<Map<String, Object>> formElementProperties = fe.propertiesForTemplateJSON();
// we'll need to update them with runtime values
final TypedData<Map<String, Object>> runtimeProperties = childComponent.getProperties();
// just for clear
childComponent.getAndClearChanges();
// add to useful properties only those formElement properties that didn't get overridden at runtime (so form element value is still used)
boolean templateValuesRemoved = false;
Iterator<Entry<String, Object>> formElementPropertyIterator = formElementProperties.content.entrySet().iterator();
while (formElementPropertyIterator.hasNext()) {
Entry<String, Object> fePropEntry = formElementPropertyIterator.next();
if (runtimeProperties.content.containsKey(fePropEntry.getKey())) {
// it has a non-default runtime value; so template value will be ignored/not sent
if (!templateValuesRemoved) {
// otherwise it's unmodifiable
formElementProperties.content = new HashMap<String, Object>(formElementProperties.content);
templateValuesRemoved = true;
}
formElementProperties.content.remove(fePropEntry.getKey());
}
}
removeRecordDependentProperties(runtimeProperties);
removeRecordDependentProperties(formElementProperties);
IWebFormUI parent = childComponent.findParent(IWebFormUI.class);
final FormElementContext formElementContext = new FormElementContext(fe, new ServoyDataConverterContext(parent.getController()), null);
componentPropertyType.writeTemplateJSONContent(writer, formElementValue, forFoundsetTypedPropertyName, formElementContext, new IModelWriter() {
@Override
public void writeComponentModel() throws JSONException {
writer.object();
DataConversion dataConversion = new DataConversion();
JSONUtils.writeData(FormElementToJSON.INSTANCE, writer, formElementProperties.content, formElementProperties.contentType, dataConversion, formElementContext);
// always use full to JSON converter here; second arg. is null due to that
childComponent.writeProperties(JSONUtils.FullValueToJSONConverter.INSTANCE, null, writer, runtimeProperties, dataConversion);
JSONUtils.writeClientConversions(writer, dataConversion);
writer.endObject();
}
}, recordBasedProperties, false);
if (forFoundsetTypedPropertyName != null)
recordBasedProperties.clearChanged();
writeWholeViewportToJSON(writer);
writer.endObject();
return writer;
}
Aggregations