BooleanField field = (BooleanField)delegate;
field.setValue(new Boolean(Context.toBoolean(value)));
} else if (delegate instanceof Repeater) {
Repeater repeater = (Repeater)delegate;
if (value instanceof NativeArray) {
NativeArray arr = (NativeArray)value;
Object length = getProperty(arr, "length");
int len = ((Number)length).intValue();
for (int i = repeater.getSize(); i >= len; --i) {
deleteRow(repeater, i);
}
for (int i = 0; i < len; i++) {
Object elemValue = getProperty(arr, i);
ScriptableWidget wid = wrap(repeater.getRow(i));
wid.jsSet_value(elemValue);
}
}
} else if (delegate instanceof AggregateField) {
AggregateField aggregateField = (AggregateField)delegate;
if (value instanceof Scriptable) {
Scriptable obj = (Scriptable)value;
Object[] ids = obj.getIds();
for (int i = 0; i < ids.length; i++) {
String id = String.valueOf(ids[i]);
Object val = getProperty(obj, id);
ScriptableWidget wid = wrap(aggregateField.getWidget(id));
if (wid == null) {
throw new JavaScriptException("No field \"" + id + "\" in widget \"" + aggregateField.getId() + "\"");
}
if (wid.delegate instanceof Field ||
wid.delegate instanceof BooleanField ||
wid.delegate instanceof Output) {
if (val instanceof Scriptable) {
Scriptable s = (Scriptable)val;
if (s.has("value", s)) {
wid.jsSet_value(s.get("value", s));
}
}
} else {
wid.jsSet_value(val);
}
}
}
} else if (delegate instanceof Repeater.RepeaterRow) {
Repeater.RepeaterRow row = (Repeater.RepeaterRow)delegate;
if (value instanceof Scriptable) {
Scriptable obj = (Scriptable)value;
Object[] ids = obj.getIds();
for (int i = 0; i < ids.length; i++) {
String id = String.valueOf(ids[i]);
Object val = getProperty(obj, id);
ScriptableWidget wid = wrap(row.getWidget(id));
if (wid == null) {
throw new JavaScriptException("No field \"" + id + "\" in row " + i + " of repeater \"" + row.getParent().getId() + "\"");
}
if (wid.delegate instanceof Field ||
wid.delegate instanceof BooleanField ||
wid.delegate instanceof Output) {
if (val instanceof Scriptable) {
Scriptable s = (Scriptable)val;
if (s.has("value", s)) {
wid.jsSet_value(s.get("value", s));
}
}
} else {
wid.jsSet_value(val);
}
}
} else {
throw new JavaScriptException("Expected an object instead of: " + Context.toString(value));
}
} else if (delegate instanceof MultiValueField) {
MultiValueField field = (MultiValueField)delegate;
Object[] values = null;
if (value instanceof NativeArray) {
NativeArray arr = (NativeArray)value;
Object length = getProperty(arr, "length");
int len = ((Number)length).intValue();
values = new Object[len];
for (int i = 0; i < len; i++) {
Object elemValue = getProperty(arr, i);