Error message "Cannot get DefaultSlingScript: Compilation errors in... cannot be resolved to a type" while creating a new component for the WKND tutorial | Community
Skip to main content
manuel_óscars89
Level 2
November 2, 2022
Question

Error message "Cannot get DefaultSlingScript: Compilation errors in... cannot be resolved to a type" while creating a new component for the WKND tutorial

  • November 2, 2022
  • 4 replies
  • 2076 views

I have created a new component for the WKND tutorial project. Its html file has the following code:

 

<sly data-sly-use.fragmentByURL="com.adobe.aem.guides.wknd.core.models.components.ContentFragmentByURL"
     data-sly-use.fragment="com.adobe.cq.wcm.core.components.models.contentfragment.ContentFragment"
     data-sly-use.cfTemplates="templates.html"
     data-sly-test.ready="${fragmentByURL.ready}">
    <sly data-sly-call="${cfTemplates.contentFragment @ fragment=fragment, fragmentPath=fragmentByURL.fragmentPath, wcmmode=wcmmode}"></sly>
</sly>
 
<sly data-sly-use.template="core/wcm/components/commons/v1/templates.html"
     data-sly-call="${template.placeholder @ isEmpty=!ready, classAppend='cq-dd-contentfragment'}"></sly>

 

I have created an interface com.adobe.aem.guides.wknd.core.models.components.ContentFragmentByURL.java that extends the interface ComponentExporter.

 

I have also created an implementation of my interface in com.adobe.aem.guides.wknd.core.models.components.impl.ContentFragmentByURLImpl.java

 

...
@Model(
adaptables = {SlingHttpServletRequest.class},
adapters = {ContentFragmentByURL.class, ComponentExporter.class},
resourceType = {ContentFragmentByURLImpl.RESOURCE_TYPE},
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL
)
@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION)
public class ContentFragmentByURLImpl implements ContentFragmentByURL{

protected static final String RESOURCE_TYPE = "wknd/components/contentfragmentbyurl";
...

I have created a package-info.java inside com.adobe.aem.guides.wknd.core.models.components.

 

I can generate the project and I can deploy it into a local AEM 6.5 instance.

 

If I go to http://localhost:4502/system/console/bundles I can see that my bundle "WKND Sites Project - Core (aem-guides-wknd.core)" is active.

 

If I go to http://localhost:4502/system/console/adapters I can see my adapters listed but the interface and its implementation appear in red color:

 

com.adobe.aem.guides.wknd.core.models.components.ContentFragmentByURL
com.adobe.cq.export.json.ComponentExporter
com.adobe.aem.guides.wknd.core.models.components.impl.ContentFragmentByURLImpl

 

If I compare it with the Byline example from the WKND tutorial, the interfacte Byline.java does not appear in red color:

 

com.adobe.aem.guides.wknd.core.models.Byline
com.adobe.aem.guides.wknd.core.models.impl.BylineImpl

 

If I go to http://localhost:4502/system/console/status-adapters I can see the interface and its implementation listed:

 

Adaptable: org.apache.sling.api.SlingHttpServletRequest
Providing Bundle: org.apache.sling.models.impl
Available Adapters:
 * com.adobe.aem.guides.wknd.core.models.components.ContentFragmentByURL
 * com.adobe.cq.export.json.ComponentExporter
 * com.adobe.aem.guides.wknd.core.models.components.impl.ContentFragmentByURLImpl

 

If I create a page and add my component, I get the following error:

 

31.10.2022 13:35:07.189 *ERROR* [127.0.0.1 [1667219707133] GET /content/wknd/language-masters/en/detalle-de-fragmento-de-contenido-04/jcr:content/root/container/contentfragmentbyurl.html HTTP/1.1] com.day.cq.wcm.core.impl.WCMDebugFilter Error during include of SlingRequestPathInfo: path='/content/wknd/language-masters/en/detalle-de-fragmento-de-contenido-04/jcr:content/root/container/contentfragmentbyurl', selectorString='null', extension='html', suffix='null'
org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: Compilation errors in org/apache/sling/scripting/sightly/apps/wknd/components/contentfragmentbyurl/contentfragmentbyurl_html.java:
Line 43, column 1927 : com.adobe.aem.guides.wknd.core.models.components.ContentFragmentByURL cannot be resolved to a type
at ...
Caused by: org.apache.sling.scripting.sightly.SightlyException: Compilation errors in org/apache/sling/scripting/sightly/apps/wknd/components/contentfragmentbyurl/contentfragmentbyurl_html.java:
Line 43, column 1927 : com.adobe.aem.guides.wknd.core.models.components.ContentFragmentByURL cannot be resolved to a type
at ... 141 common frames omitted

 

Can anybody, please, spot what I am missing?

 

Thanks in advance.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

4 replies

manuel_óscars89
Level 2
November 2, 2022

My local instance is an Adobe Experience Manager 6.5.14.0 and I am using the latest WKND tutorial code available at https://github.com/adobe/aem-guides-wknd.

SantoshSai
Community Advisor
Community Advisor
November 2, 2022

Hi @manuel_óscars89,

I believe the implementation is not correct.

The proper way to extend Core Components model is to use delegation pattern. Here is the similar question answered, kindly have a look [0].

[0]: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/com-adobe-cq-wcm-core-components-internal-cannot-be-resolved/m-p/555825/highlight/true#M137990

Hope that helps!

Regards,

Santosh

Santosh Sai
manuel_óscars89
Level 2
November 2, 2022

Hi! I am not extending a Core Component. There is a project called Asset Share Commons (https://opensource.adobe.com/asset-share-commons/) in which they manage to show different images or videos using just one page instead of using one page per each image.

 

Example: https://aem.enablementadobe.com/content/asset-share-commons/en/light/details/image.html/content/dam/asset-share-commons/en/public/pictures/alex-holyoake-157978.jpg

 

The way they have done this is by creating new components whose only purpose is to get an asset path for the URL suffix and then find that asset and render it.

 

I am trying to do the same for Content Fragments, which are another kind of asset in the DAM.

 

They did not extend the current Core Components but created new components. Here you can see a code example for images:

 

https://github.com/adobe/asset-share-commons/tree/develop/ui.apps/src/main/content/jcr_root/apps/asset-share-commons/components/details/image

 

https://github.com/adobe/asset-share-commons/blob/develop/core/src/main/java/com/adobe/aem/commons/assetshare/components/details/Image.java

 

https://github.com/adobe/asset-share-commons/blob/develop/core/src/main/java/com/adobe/aem/commons/assetshare/components/details/impl/ImageImpl.java

 

I am trying to replicate their success but for Content Fragments.

 

Thanks in advance for any help.

 

May 5, 2023

I faced same problem and I checked every thing; osgi bundles and web console sling adapters. Every thing seems correct and I was still facing the problem. And after adding package-info.java in my sub folder of sling model error disappeared.

 

Before adding the package-info.java my custom sling model appears red in http://localhost:4502/system/console/adapters. After adding the file the color change to black. I searched a lot why this color is red but I could not find.