Uploaded image for project: 'Tapestry'
  1. Tapestry
  2. TAPESTRY-2298

Can't use the callback option of AJAX.AutoComplete, because there is no way to produce a quoteless value in a JSONObject

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Duplicate
    • 5.0.12
    • None
    • tapestry-core
    • 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()

      { 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.

      All that is needed is JSONString.class in ALLOWED.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              woodj Julian Wood
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Slack

                  Issue deployment