Tapestry 5
  1. Tapestry 5
  2. 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)

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 5.0.15
    • Fix Version/s: 5.1.0.2
    • Component/s: None
    • Labels:
      None

      Description

      the JSONObject config in mixin Autocomplete surrounds parameters with double qoute.
      so Ajax.Autocompleter dont know how to interpreting the callbacks like "afterUpdateElement"
      and throws an exception "function not found".

        Issue Links

          Activity

          Hide
          Davor Hrg added a comment -

          I did find a solution that does not require a patch

          /** Workarround to add raw content to JSON, like function references and such.

          • Number instances are not quoted and are trusted, so we use it.*/
            final class JSONRaw extends Number {

          private final String rawText;

          JSONRaw(String rawText)

          { this.rawText = rawText; }

          @Override public double doubleValue()

          {return 0;}

          @Override public float floatValue() {return 0;}

          @Override public int intValue()

          {return 0;}

          @Override public long longValue() {return 0;}

          @Override public String toString()

          { return rawText; }

          }

          Show
          Davor Hrg added a comment - I did find a solution that does not require a patch /** Workarround to add raw content to JSON, like function references and such. Number instances are not quoted and are trusted, so we use it.*/ final class JSONRaw extends Number { private final String rawText; JSONRaw(String rawText) { this.rawText = rawText; } @Override public double doubleValue() {return 0;} @Override public float floatValue() {return 0;} @Override public int intValue() {return 0;} @Override public long longValue() {return 0;} @Override public String toString() { return rawText; } }
          Hide
          Nicolas Charles added a comment -

          Yes, it would be so convenient to authorise JSONString into the JSONObject, or at least a new classe implementing JSONString and not quoting the text. Currently, i'm fighting with this because i need to pass a Prototype object to a method and it gets quoted...

          Show
          Nicolas Charles added a comment - Yes, it would be so convenient to authorise JSONString into the JSONObject, or at least a new classe implementing JSONString and not quoting the text. Currently, i'm fighting with this because i need to pass a Prototype object to a method and it gets quoted...
          Hide
          Julian Wood added a comment -

          So, any way to get this fix included? It's been a problem for a while, and you still can't send a configuration to the autocomplete. It's obviously a pain keeping a separate JSONObject copy around (which necessitates a copy of JSONArray, etc). We've been using this fix for, well, 9 months now and it seems strong. Any reason why this tiny little patch can't be applied?

          Show
          Julian Wood added a comment - So, any way to get this fix included? It's been a problem for a while, and you still can't send a configuration to the autocomplete. It's obviously a pain keeping a separate JSONObject copy around (which necessitates a copy of JSONArray, etc). We've been using this fix for, well, 9 months now and it seems strong. Any reason why this tiny little patch can't be applied?
          Hide
          Julian Wood added a comment -

          This patch offers a solution to the issue. It makes only 2 small changes to JSONObject to accomplish this.

          1. Add JSONString to the list of allowed objects in the config.

          2. When doing toString (and subsequent valueToString), if the object is a JSONString, don't quote it's toJSONString method.

          • given it was impossible to execute this piece of code prior to making JSONString an allowable object, I don't think this can hurt anything.

          Now you can extend autocomplete and override configure properly:

          protected void configure(JSONObject config) {
          config.put("updateElement", new JSONString() {
          public String toJSONString()

          { return "hello"; }

          });
          }

          This will call the hello method in your javascript when you choose something from the autocomplete dropdown:

          function hello()

          { alert('hello'); }

          Of course, in the case of autocomplete, this allows you to substitute your methods for many of the configurable options in the prototype autocomplete, something which is impossible right now.

          Show
          Julian Wood added a comment - This patch offers a solution to the issue. It makes only 2 small changes to JSONObject to accomplish this. 1. Add JSONString to the list of allowed objects in the config. 2. When doing toString (and subsequent valueToString), if the object is a JSONString, don't quote it's toJSONString method. given it was impossible to execute this piece of code prior to making JSONString an allowable object, I don't think this can hurt anything. Now you can extend autocomplete and override configure properly: protected void configure(JSONObject config) { config.put("updateElement", new JSONString() { public String toJSONString() { return "hello"; } }); } This will call the hello method in your javascript when you choose something from the autocomplete dropdown: function hello() { alert('hello'); } Of course, in the case of autocomplete, this allows you to substitute your methods for many of the configurable options in the prototype autocomplete, something which is impossible right now.
          Hide
          Howard M. Lewis Ship added a comment -

          TAPESTRY-2129 is correct; the problem is that the config object for Autocomplete is a JavaScript object, not a JSON Object. The difference is the ability to assign a function to a property, rather than a string, number, array or nested JSON object.

          Show
          Howard M. Lewis Ship added a comment - TAPESTRY-2129 is correct; the problem is that the config object for Autocomplete is a JavaScript object, not a JSON Object. The difference is the ability to assign a function to a property, rather than a string, number, array or nested JSON object.
          Hide
          Andreas Andreou added a comment -

          Actually, this is the same as TAPESTRY-2129 which seems to have been incorrectly closed

          Show
          Andreas Andreou added a comment - Actually, this is the same as TAPESTRY-2129 which seems to have been incorrectly closed

            People

            • Assignee:
              Howard M. Lewis Ship
              Reporter:
              Sven Homburg
            • Votes:
              10 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development