aem-core-wcm-components icon indicating copy to clipboard operation
aem-core-wcm-components copied to clipboard

Categories object not populated when using com.adobe.cq.wcm.core.components.models.ClientLibraries.

Open gmartinelo opened this issue 3 years ago • 4 comments

Bug Report

Current Behavior

The 'categories' property never gets populated with the desired values in the model and it seems to be instanciated with an object of type com.day.cq.i18n.

I'm following this documentation: https://experienceleague.adobe.com/docs/experience-manager-core-components/using/developing/including-clientlibs.html?lang=en

<sly data-sly-use.clientlibs="${'com.adobe.cq.wcm.core.components.models.ClientLibraries' @ categories='otf.vanilla.homepage', async=true}"> ${clientlibs.jsIncludes @ context="unsafe"} </sly>

The resourceTypes property seems to have the same behavior described previously. Async, defer, crossorigin,media and onload are populated correctly.

Expected behavior/code Categories object should have the values passed from HTL.

Environment

  • AEM version and patch level: 6.5.8
  • Core Components version: 2.17.8
  • JRE version: Java(TM) SE Runtime Environment 18.9 (build 11.0.10+8-LTS-162)

Additional context / Screenshots Page.html image

ClientLibrariesImpl.java image

image

image

gmartinelo avatar Aug 31 '21 15:08 gmartinelo

I am seeing the exact same behaviour, this is not working indeed. Was trying something similar as described here: https://github.com/adobe/aem-core-wcm-components/blob/9dd529595b65a8441bd320b602584c2d568b6361/extensions/amp/README.md

<style amp-custom data-sly-use.clientlibs="${'com.adobe.cq.wcm.core.components.models.ClientLibraries' @ categories='cmp-examples.base.amp'}"> ${clientlibs.cssInline @ context="unsafe"} </style>

Jdruwe avatar Sep 24 '21 08:09 Jdruwe

I see the same issue when the named property is not set in data-sly-call attributes.

For example, the code posted above works properly for me (insofar as it properly sets the categories field in the model); however the resourceTypes field just has some other object injected. In my case that is the ReferrerFilter.ConfigurationPrinter.

If I change the htl to set the resourceTypes attribute but not the categories attribute, then the categories field in the model has a seemingly random object injected.

My suspicion is that since both the categories and resourceTypes field types are Object, it might just be sticking in something / anything / whatever is at the top of some list. Since the field type is Object it can stick anything in there.

This might be an issue for Sling, to make sure that an object isn't injected unless the name matches - even if the object type is compatible with something else.

This is all just speculation, I didn't step through the entire field injection resolution.

That said, changing the @Inject annotation in ClientLibrariesImpl resolves the random object injection in my tests. Example:

public class ClientLibrariesImpl implements ClientLibraries {

    // ....

    @RequestAttribute(injectionStrategy = InjectionStrategy.OPTIONAL, name = OPTION_RESOURCE_TYPES)
    Object resourceTypes;

    // ....

    @RequestAttribute(injectionStrategy = InjectionStrategy.OPTIONAL, name = OPTION_CATEGORIES)
    private Object categories;

    // ....
}

@gmartinelo, do those changes resolve your issue?

ky940819 avatar Oct 02 '21 02:10 ky940819

@ky940819 sorry for the late response. Yes, I see the right object in the model with those changes. Thank you.

gmartinelo avatar Oct 26 '21 16:10 gmartinelo

This is still not working! I always see this in the logs - "No categories detected. Please either specify the categories as a CSV string or a set of resource types for looking them up!" even when passing the right category from HTL

gunakar89 avatar Aug 04 '22 07:08 gunakar89

I still see this issue. My environment is as follows Archetype:41 AEM 6.5.15 AEM core components 2.22.0 Any update on this issue

shajiahmed avatar May 16 '23 02:05 shajiahmed