Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

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

Avatar

Level 2

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.

4 Replies

Avatar

Level 2

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.

Avatar

Community Advisor

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-comp...

Hope that helps!

Regards,

Santosh

Avatar

Level 2

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/...

 

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/ass...

 

https://github.com/adobe/asset-share-commons/blob/develop/core/src/main/java/com/adobe/aem/commons/a...

 

https://github.com/adobe/asset-share-commons/blob/develop/core/src/main/java/com/adobe/aem/commons/a...

 

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

 

Thanks in advance for any help.