Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Duplicate
-
5.0.12
-
None
-
None
-
osx 10.5, java 1.5
Description
If you extend Autocomplete, and override the configure method like so:
protected void configure(JSONObject config)
{ config.put("callback", "myMethod"); }and in my javascript I have:
function myMethod(element, entry) {
console.info(element);
console.info(entry);
return entry;
}
This doesn't work because myMethod is quoted in javascript, and needs to be unquoted:
new AJAX.AutoComplete('provinceState', 'provinceState:menu', '/webapp/signup.provincestate:autocomplete',
{"indicator":"provinceState:loader","callback":"myMethod","paramName":"t:input"});
should be
new AJAX.AutoComplete('provinceState', 'provinceState:menu', '/webapp/signup.provincestate:autocomplete',
{"indicator":"provinceState:loader","callback":myMethod,"paramName":"t:input"});
Note the absence of quotes around myMethod.
So it seems I should be able to put an object into the config which returns an unquoted string:
protected void configure(JSONObject config)
{
config.put("callback", new JSONString() {
public String toJSONString()
});
}
However, this errors because the allowed types for the JSONObject.put method seem restricted to these:
private static final Class[] ALLOWED = new Class[]
{ String.class, Boolean.class, Number.class, JSONObject.class, JSONArray.class, Null.class };
This, despite the fact that the method JSONObject.valueToString(Object value) looks for an object of type JSONString.
I can't extend JSONObject with my own toJSONString() impl, because JSONObject is final.
All that is needed is JSONString.class in ALLOWED.
Attachments
Issue Links
- duplicates
-
TAP5-39 Add JSON support for literals (often, inline function definitions) that are used to configure some client-side objects (even if they aren't truly JSON)
- Closed