adobe / aem-core-wcm-components

Standardized components to build websites with AEM.
https://docs.adobe.com/content/help/en/experience-manager-core-components/using/introduction.html
Apache License 2.0
743 stars 750 forks source link

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

Closed gmartinelo closed 1 year ago

gmartinelo commented 3 years ago

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

Additional context / Screenshots Page.html image

ClientLibrariesImpl.java image

image

image

Jdruwe commented 3 years ago

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>

ky940819 commented 3 years ago

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?

gmartinelo commented 3 years ago

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

gunakar89 commented 2 years ago

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

shajiahmed commented 1 year ago

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