You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Eric Norman (Jira)" <ji...@apache.org> on 2021/08/07 21:22:00 UTC
[jira] [Resolved] (SLING-10677) add support for using an enum class
via the Java Use-API
[ https://issues.apache.org/jira/browse/SLING-10677?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Norman resolved SLING-10677.
---------------------------------
Resolution: Fixed
Merged PR at: [{{8e1965c}}|https://github.com/apache/sling-org-apache-sling-scripting-sightly/commit/8e1965cc1285eb16b79ee018b061200f43aeb596]
> 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.10-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)