Tapestry 5
  1. Tapestry 5
  2. TAP5-887

Easier way to initialize a JSONObject with keys and values

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 5.2.0
    • Fix Version/s: 5.2.0
    • Component/s: tapestry-core
    • Labels:
      None

      Description

      Perhaps a static factory method that tooks keys/values.

        Activity

        Hide
        Leonard Lu added a comment -

        I would suggest adding a type coercer to TapestryModule. This would at least make writing Tapestry components that integrate or wrap Javascript libraries easier to write.
        ======================================================================
        public static void contributeTypeCoercer(Configuration<CoercionTuple> configuration) {
        configuration.add(new CoercionTuple<String,JSONObject>(
        String.class,
        JSONObject.class,
        new Coercion<String, JSONObject>(){
        public JSONObject coerce(String input)

        { return new JSONObject(input); }

        }
        ));
        }
        ======================================================================

        which would allow for templates like:
        <t:mycomponent
        t:mixins="highlightEffectMixin"
        jsonObject="literal:

        {startcolor:'#00FF00',endcolor:'#FFFFFF',restorecolor:'#FFFFFF',duration:3.0}

        "
        />

        Show
        Leonard Lu added a comment - I would suggest adding a type coercer to TapestryModule. This would at least make writing Tapestry components that integrate or wrap Javascript libraries easier to write. ====================================================================== public static void contributeTypeCoercer(Configuration<CoercionTuple> configuration) { configuration.add(new CoercionTuple<String,JSONObject>( String.class, JSONObject.class, new Coercion<String, JSONObject>(){ public JSONObject coerce(String input) { return new JSONObject(input); } } )); } ====================================================================== which would allow for templates like: <t:mycomponent t:mixins="highlightEffectMixin" jsonObject="literal: {startcolor:'#00FF00',endcolor:'#FFFFFF',restorecolor:'#FFFFFF',duration:3.0} " />
        Hide
        Howard M. Lewis Ship added a comment -

        This was addressed at some prior point by adding a constuctor to JSON object that accepts an even number of values (alternating string keys and values).

        A String->JSONObject coercion would be easy, but should be added as a separate issue.

        Show
        Howard M. Lewis Ship added a comment - This was addressed at some prior point by adding a constuctor to JSON object that accepts an even number of values (alternating string keys and values). A String->JSONObject coercion would be easy, but should be added as a separate issue.

          People

          • Assignee:
            Howard M. Lewis Ship
            Reporter:
            Howard M. Lewis Ship
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development