Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
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
- relates to
-
SLING-10678 enhance ObjectModel#resolveProperty to handle target that is an enum class
-
- Closed
-
- links to
1.
|
add integration content for testing |
|
Closed | Eric Norman |
|
|||||||
2.
|
add integration tests to verify |
|
Closed | Eric Norman |
|