I was just extending Autocomplete, and I wanted to add a callback to the config, so I override the config:

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() {
                return "myMethod";
            }
        });
    }

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.

Bug? All that is needed is JSONString.class in ALLOWED.

Thanks,

J




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to