[ 
https://issues.apache.org/jira/browse/SLING-12302?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Karol Lewandowski updated SLING-12302:
--------------------------------------
    Description: 
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}
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="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">
    <nested
            jcr:primaryType="sling:OsgiConfig"
            greeting="hello"/>
</jcr:root>
{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.

  was:
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}
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="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">
    <nested
            jcr:primaryType="sling:OsgiConfig"
            greeting="hello"/>
</jcr:root>
{code}
and reference it from some path.

2. Access in HTL without configuration annotation class:
{code:java}
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:java}
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:java}
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.


> 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}
> <?xml version="1.0" encoding="UTF-8"?>
> <jcr:root xmlns:sling="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">
>     <nested
>             jcr:primaryType="sling:OsgiConfig"
>             greeting="hello"/>
> </jcr:root>
> {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)

Reply via email to