[jira] [Commented] (SLING-12302) CA Config access syntax is inconsistent in HTL
[ https://issues.apache.org/jira/browse/SLING-12302?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17845977#comment-17845977 ] Stefan Seifert commented on SLING-12302: for 1.: this looks like a bug, i assume that it probably not only affects HTL context, but in general. i think it would be worth creating a dedicated issue for it, probably with a unit test case, if possible. for 2: i'm not sure how much this syntax to fetch complex caconfigs directly from HTL is used in practice - probably not so much, esp. considering the fact you are the first asking that detailed questions after all that years it's available... i think there is no easy way to iterate over nested child lists, and currently we do not plan to add support for that, unless there is a high need. i think in most cases caconfigs are consumed in sling models, and consumed in HTL from there. a benefit of that approach is to use strong typing and compile-time check. > CA Config access syntax is inconsistent in HTL > -- > > Key: SLING-12302 > URL: https://issues.apache.org/jira/browse/SLING-12302 > Project: Sling > Issue Type: Bug >Reporter: Karol Lewandowski >Assignee: Stefan Seifert >Priority: Major > > I have a problem understanding how nested configs can be accessed in HTL or > if there is a bug in the implementation. > The > [documentation|https://sling.apache.org/documentation/bundles/context-aware-configuration/context-aware-configuration.html#accessing-configuration-from-htlsightly-templates] > gives an example: > {{{}$\{caconfig['x.y.z.ConfigSample']['nestedConfig/stringParam']{ > However, it doesn't work when a configuration annotation class is defined. > Steps to reproduce: > 1. Create a config node: > {{/conf/we-retail/sling:configs/us/en/sling:configs/com.mysite.core.config.TestConfig}} > {code:xml} > > http://sling.apache.org/jcr/sling/1.0; > xmlns:jcr="http://www.jcp.org/jcr/1.0; > jcr:primaryType="sling:OsgiConfig" > email="t...@example.com" > enabled="{Boolean}true" > number="{Long}123"> > jcr:primaryType="sling:OsgiConfig" > greeting="hello"/> > > {code} > and reference it from some path. > 2. Access in HTL without configuration annotation class: > {code} > Email: ${caconfig['com.mysite.core.config.TestConfig'].email} > Number: ${caconfig['com.mysite.core.config.TestConfig'].number} > Enabled: ${caconfig['com.mysite.core.config.TestConfig'].enabled} > Greeting (config path): > ${caconfig['com.mysite.core.config.TestConfig/nested'].greeting} > Greeting (property path): > ${caconfig['com.mysite.core.config.TestConfig']['nested/greeting']} {code} > This gives the output: > {code} > Email: t...@example.com > Number: 123 > Enabled: true > Greeting (config path): hello > Greeting (property path): hello {code} > It works as expected. > 3. Create annotation classes: > {code:java} > package com.mysite.core.config; > import org.apache.sling.caconfig.annotation.Configuration; > @Configuration > public @interface TestConfig { > String email(); > int number() default 5; > boolean enabled(); > NestedConfig nested(); > } > {code} > and > {code:java} > package com.mysite.core.config; > public @interface NestedConfig { > String greeting(); > } > {code} > The previous HTL will print: > {code} > Email: t...@example.com > Number: 123 > Enabled: true > Greeting (config path): hello > Greeting (property path): {code} > Accessing nested config value with property name path doesn't work. Is it > expected? > I'm working on support for CA Configs in AEM IDE, so I don't want to make it > work in my AEM application but provide the correct syntax support. -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (SLING-12302) CA Config access syntax is inconsistent in HTL
[ https://issues.apache.org/jira/browse/SLING-12302?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17843164#comment-17843164 ] Karol Lewandowski commented on SLING-12302: --- Hi, I have additional questions, if you don't mind. If there is a better channel for this, please let me know. 1. I noticed that accessing nested configuration takes metadata from the parent config resources. Examples: 1. {{{}$\{caconfig['com.example.Config/nested']{ - this will take default values from {{com.example.Config}} annotation. 2. {{{}$\{caconfig['com.example.Config/nested/subnested']{ - this will also take default values from {{com.example.Config}} annotation. This is the code responsible for this behavior: [https://github.com/apache/sling-org-apache-sling-caconfig-impl/blob/master/src/main/java/org/apache/sling/caconfig/impl/ConfigurationBuilderImpl.java#L259-L269] Correct me if I'm wrong, but I think that it is quite uncommon for nested configuration resource properties to match the keys of parent properties. There is a comment: "probably a configuration list - remove item name from end", but it is unclear. Why a nested configuration is considered a potential list and how is it related to default values of the parent? 2. Is it expected that it is not possible to iterate nested configurations in HTL? I mean something like this: - /conf/we-retail/sling:configs/us/en/sling:configs -- com.example.Config --- nestedList item1 item2 item3 Annotations: {code:java} package com.example; import org.apache.sling.caconfig.annotation.Configuration; @Configuration public @interface Config { NestedConfig[] nestedList(); } {code} {code:java} package com.example; public @interface NestedConfig { String message(); } {code} Access in HTL: {code:java} ${item.message} {code} Unfortunately, it doesn't work. The iteration is performed on the {{com.example.Config/nestedList}} resource instead of items, which is an iteration over its value map keys. Is it expected? Is creating a Sling Model the only way to iterate over a nested list? > CA Config access syntax is inconsistent in HTL > -- > > Key: SLING-12302 > URL: https://issues.apache.org/jira/browse/SLING-12302 > Project: Sling > Issue Type: Bug >Reporter: Karol Lewandowski >Assignee: Stefan Seifert >Priority: Major > > I have a problem understanding how nested configs can be accessed in HTL or > if there is a bug in the implementation. > The > [documentation|https://sling.apache.org/documentation/bundles/context-aware-configuration/context-aware-configuration.html#accessing-configuration-from-htlsightly-templates] > gives an example: > {{{}$\{caconfig['x.y.z.ConfigSample']['nestedConfig/stringParam']{ > However, it doesn't work when a configuration annotation class is defined. > Steps to reproduce: > 1. Create a config node: > {{/conf/we-retail/sling:configs/us/en/sling:configs/com.mysite.core.config.TestConfig}} > {code:xml} > > http://sling.apache.org/jcr/sling/1.0; > xmlns:jcr="http://www.jcp.org/jcr/1.0; > jcr:primaryType="sling:OsgiConfig" > email="t...@example.com" > enabled="{Boolean}true" > number="{Long}123"> > jcr:primaryType="sling:OsgiConfig" > greeting="hello"/> > > {code} > and reference it from some path. > 2. Access in HTL without configuration annotation class: > {code} > Email: ${caconfig['com.mysite.core.config.TestConfig'].email} > Number: ${caconfig['com.mysite.core.config.TestConfig'].number} > Enabled: ${caconfig['com.mysite.core.config.TestConfig'].enabled} > Greeting (config path): > ${caconfig['com.mysite.core.config.TestConfig/nested'].greeting} > Greeting (property path): > ${caconfig['com.mysite.core.config.TestConfig']['nested/greeting']} {code} > This gives the output: > {code} > Email: t...@example.com > Number: 123 > Enabled: true > Greeting (config path): hello > Greeting (property path): hello {code} > It works as expected. > 3. Create annotation classes: > {code:java} > package com.mysite.core.config; > import org.apache.sling.caconfig.annotation.Configuration; > @Configuration > public @interface TestConfig { > String email(); > int number() default 5; > boolean enabled(); > NestedConfig nested(); > } > {code} > and > {code:java} > package com.mysite.core.config; > public @interface NestedConfig { > String greeting(); > } > {code} > The previous HTL will print: > {code} > Email: t...@example.com > Number: 123 > Enabled: true > Greeting (config path): hello > Greeting (property path): {code} > Accessing nested config value with property name path doesn't work. Is it > expected? > I'm working on support for CA Configs in AEM IDE, so I don't want to make it > work in my AEM application but provide
[jira] [Commented] (SLING-12302) CA Config access syntax is inconsistent in HTL
[ https://issues.apache.org/jira/browse/SLING-12302?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17840487#comment-17840487 ] Karol Lewandowski commented on SLING-12302: --- Thanks for the answer and the side note (I copied it from some unofficial example and wasn't aware it was incorrect). I provided the PR with the fix in the documentation: [https://github.com/apache/sling-site/pull/160] > CA Config access syntax is inconsistent in HTL > -- > > Key: SLING-12302 > URL: https://issues.apache.org/jira/browse/SLING-12302 > Project: Sling > Issue Type: Bug >Reporter: Karol Lewandowski >Priority: Major > > I have a problem understanding how nested configs can be accessed in HTL or > if there is a bug in the implementation. > The > [documentation|https://sling.apache.org/documentation/bundles/context-aware-configuration/context-aware-configuration.html#accessing-configuration-from-htlsightly-templates] > gives an example: > {{{}$\{caconfig['x.y.z.ConfigSample']['nestedConfig/stringParam']{ > However, it doesn't work when a configuration annotation class is defined. > Steps to reproduce: > 1. Create a config node: > {{/conf/we-retail/sling:configs/us/en/sling:configs/com.mysite.core.config.TestConfig}} > {code:xml} > > http://sling.apache.org/jcr/sling/1.0; > xmlns:jcr="http://www.jcp.org/jcr/1.0; > jcr:primaryType="sling:OsgiConfig" > email="t...@example.com" > enabled="{Boolean}true" > number="{Long}123"> > jcr:primaryType="sling:OsgiConfig" > greeting="hello"/> > > {code} > and reference it from some path. > 2. Access in HTL without configuration annotation class: > {code} > Email: ${caconfig['com.mysite.core.config.TestConfig'].email} > Number: ${caconfig['com.mysite.core.config.TestConfig'].number} > Enabled: ${caconfig['com.mysite.core.config.TestConfig'].enabled} > Greeting (config path): > ${caconfig['com.mysite.core.config.TestConfig/nested'].greeting} > Greeting (property path): > ${caconfig['com.mysite.core.config.TestConfig']['nested/greeting']} {code} > This gives the output: > {code} > Email: t...@example.com > Number: 123 > Enabled: true > Greeting (config path): hello > Greeting (property path): hello {code} > It works as expected. > 3. Create annotation classes: > {code:java} > package com.mysite.core.config; > import org.apache.sling.caconfig.annotation.Configuration; > @Configuration > public @interface TestConfig { > String email(); > int number() default 5; > boolean enabled(); > NestedConfig nested(); > } > {code} > and > {code:java} > package com.mysite.core.config; > public @interface NestedConfig { > String greeting(); > } > {code} > The previous HTL will print: > {code} > Email: t...@example.com > Number: 123 > Enabled: true > Greeting (config path): hello > Greeting (property path): {code} > Accessing nested config value with property name path doesn't work. Is it > expected? > I'm working on support for CA Configs in AEM IDE, so I don't want to make it > work in my AEM application but provide the correct syntax support. -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (SLING-12302) CA Config access syntax is inconsistent in HTL
[ https://issues.apache.org/jira/browse/SLING-12302?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17840363#comment-17840363 ] Stefan Seifert commented on SLING-12302: the first syntax {noformat} ${caconfig['com.mysite.core.config.TestConfig/nested'].greeting} {noformat} should be used. that the second syntax with {{['nested/greeting']}} is working is probably only by chance, as a normal value map is used if not annotation class is used, and that supports by default accessing deeper resource hierarchy levels via property access. this is not the case if annotation class is used, because there the value map is constructed by other means, e.g. to support the default values that may be defined in the annotation class. sidenote: you should not use {{jcr:primaryType="sling:OsgiConfig"}} in context of caconfig - it's only use is for defining osgi configurations in the JCR repository, so using it here could have unwanted side-effect. just use nt:unstructured (unless you are using a different persistence strategy e.g. https://wcm.io/caconfig/extensions/ for storing in cq:Page objects). > CA Config access syntax is inconsistent in HTL > -- > > Key: SLING-12302 > URL: https://issues.apache.org/jira/browse/SLING-12302 > Project: Sling > Issue Type: Bug >Reporter: Karol Lewandowski >Priority: Major > > I have a problem understanding how nested configs can be accessed in HTL or > if there is a bug in the implementation. > The > [documentation|https://sling.apache.org/documentation/bundles/context-aware-configuration/context-aware-configuration.html#accessing-configuration-from-htlsightly-templates] > gives an example: > {{{}$\{caconfig['x.y.z.ConfigSample']['nestedConfig/stringParam']{ > However, it doesn't work when a configuration annotation class is defined. > Steps to reproduce: > 1. Create a config node: > {{/conf/we-retail/sling:configs/us/en/sling:configs/com.mysite.core.config.TestConfig}} > {code:xml} > > http://sling.apache.org/jcr/sling/1.0; > xmlns:jcr="http://www.jcp.org/jcr/1.0; > jcr:primaryType="sling:OsgiConfig" > email="t...@example.com" > enabled="{Boolean}true" > number="{Long}123"> > jcr:primaryType="sling:OsgiConfig" > greeting="hello"/> > > {code} > and reference it from some path. > 2. Access in HTL without configuration annotation class: > {code} > Email: ${caconfig['com.mysite.core.config.TestConfig'].email} > Number: ${caconfig['com.mysite.core.config.TestConfig'].number} > Enabled: ${caconfig['com.mysite.core.config.TestConfig'].enabled} > Greeting (config path): > ${caconfig['com.mysite.core.config.TestConfig/nested'].greeting} > Greeting (property path): > ${caconfig['com.mysite.core.config.TestConfig']['nested/greeting']} {code} > This gives the output: > {code} > Email: t...@example.com > Number: 123 > Enabled: true > Greeting (config path): hello > Greeting (property path): hello {code} > It works as expected. > 3. Create annotation classes: > {code:java} > package com.mysite.core.config; > import org.apache.sling.caconfig.annotation.Configuration; > @Configuration > public @interface TestConfig { > String email(); > int number() default 5; > boolean enabled(); > NestedConfig nested(); > } > {code} > and > {code:java} > package com.mysite.core.config; > public @interface NestedConfig { > String greeting(); > } > {code} > The previous HTL will print: > {code} > Email: t...@example.com > Number: 123 > Enabled: true > Greeting (config path): hello > Greeting (property path): {code} > Accessing nested config value with property name path doesn't work. Is it > expected? > I'm working on support for CA Configs in AEM IDE, so I don't want to make it > work in my AEM application but provide the correct syntax support. -- This message was sent by Atlassian Jira (v8.20.10#820010)