Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-10677

add support for using an enum class via the Java Use-API

    XMLWordPrintableJSON

Details

    Description

      For a use case where you need access to an enum value in your ui script for some reason, it would be nice to be able to "data-sly-use" your enum class with something like this:

       

      <sly data-sly-use.myEnum="org.hello.MyEnum"></sly>
      

      ... and then later on you can reference the enum values with an expression that looks something like this:

      <p>
       Enum value by name: ${myEnum.SOMEVALUE}
      </p>
      <p>
       Enum value by ordinal: ${myEnum[1]}
      </p>
      <p>
       Constant static field within the enum: ${myEnum.SOME_NON_VALUE_CONSTANT_FIELD}
      </p>
      
      <p data-sly-repeat.value="${myEnum.values}">
           Enum value[${value.ordinal}] from static method call: ${value}
      </p>
      

      Since the enum can not have a default constructor, special handling in JavaUseProvider would be required to return the enum class itself instead of trying to instantiate a new instance of the class.

       

      NOTE: A companion fix will also be required in org.apache.sling.scripting.sightly.render.ObjectModel#resolveProperty to deal with the target object being an Enum class instead of a POJO object in order for the expressions to resolve as expected.

      Attachments

        Issue Links

          Activity

            People

              enorman Eric Norman
              enorman Eric Norman
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 6h 10m
                  6h 10m