[ https://issues.apache.org/jira/browse/SLING-10677?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Norman closed SLING-10677. ------------------------------- Closing with 1.4.12-1.4.0 release > add support for using an enum class via the Java Use-API > -------------------------------------------------------- > > Key: SLING-10677 > URL: https://issues.apache.org/jira/browse/SLING-10677 > Project: Sling > Issue Type: Improvement > Components: Scripting > Reporter: Eric Norman > Assignee: Eric Norman > Priority: Major > Fix For: Scripting HTL Engine 1.4.12-1.4.0 > > Time Spent: 3h 10m > Remaining Estimate: 0h > > 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: > > {code:java} > <sly data-sly-use.myEnum="org.hello.MyEnum"></sly> > {code} > ... and then later on you can reference the enum values with an expression > that looks something like this: > {code:java} > <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> > {code} > 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. -- This message was sent by Atlassian Jira (v8.3.4#803005)