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

          Sven Homburg created issue -
          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
          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.
          Howard M. Lewis Ship made changes -
          Field Original Value New Value
          Affects Version/s 5.0.11 [ 12312968 ]
          Howard M. Lewis Ship made changes -
          Fix Version/s 5.0.12 [ 12313048 ]
          Fix Version/s 5.0.11 [ 12312968 ]
          Howard M. Lewis Ship made changes -
          Fix Version/s 5.0.13 [ 12313205 ]
          Fix Version/s 5.0.12 [ 12313048 ]
          Howard M. Lewis Ship made changes -
          Fix Version/s 5.0.13 [ 12313205 ]
          Fix Version/s 5.0 [ 12312018 ]
          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.
          Julian Wood made changes -
          Attachment TAPESTRY-2234-tapestry-project.patch [ 12383703 ]
          Howard M. Lewis Ship made changes -
          Affects Version/s 5.0 [ 12312018 ]
          Howard M. Lewis Ship made changes -
          Project Tapestry [ 10573 ] Tapestry 5 [ 12310833 ]
          Fix Version/s 5.0 [ 12312018 ]
          Affects Version/s 5.0 [ 12312018 ]
          Component/s XHR/dhtml/Ajax [ 12311531 ]
          Key TAPESTRY-2234 TAP5-39
          Howard M. Lewis Ship made changes -
          Affects Version/s 5.0.15 [ 12313429 ]
          Julian Wood made changes -
          Link This issue is duplicated by TAPESTRY-2298 [ TAPESTRY-2298 ]
          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
          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
          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; } }
          Howard M. Lewis Ship made changes -
          Assignee Howard M. Lewis Ship [ hlship ]
          Howard M. Lewis Ship made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          Howard M. Lewis Ship made changes -
          Summary Autocomplete / JSONObject config surrounds parameter with double qoute 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)
          Howard M. Lewis Ship made changes -
          Status In Progress [ 3 ] Closed [ 6 ]
          Fix Version/s 5.1.0.2 [ 12313706 ]
          Resolution Fixed [ 1 ]
          Transition Time In Source Status Execution Times Last Executer Last Execution Date
          Open Open In Progress In Progress
          385d 26m 1 Howard M. Lewis Ship 24/Mar/09 21:44
          In Progress In Progress Closed Closed
          2h 25m 1 Howard M. Lewis Ship 25/Mar/09 00:09

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Development