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
BedrockMission!

Learn More

View all

Sign in to view all badges

How to adapt OOTB ContentFragmentList sling model in another sling model

Avatar

Avatar
Boost 1
Level 1
Vikash_kumar_18
Level 1

Like

1 like

Total Posts

3 posts

Correct Reply

0 solutions
Top badges earned
Boost 1
View profile

Avatar
Boost 1
Level 1
Vikash_kumar_18
Level 1

Like

1 like

Total Posts

3 posts

Correct Reply

0 solutions
Top badges earned
Boost 1
View profile
Vikash_kumar_18
Level 1

28-05-2021

Hi,

I am trying to adapt OOTB ContentFragmentList sling model.

I am extending OOTB ContentFragmentList.

Vikash_kumar_18_0-1622232178706.png

At Line 28, While evaluating the right side, I am getting the expected result as a List of content fragments. But it's throwing below exception while assigning the value to the right side.

Caused by: java.lang.ClassCastException: com.adobe.cq.wcm.core.components.internal.models.v1.contentfragment.ContentFragmentListImpl cannot be cast to com.adobe.cq.wcm.core.components.models.contentfragment.ContentFragmentList

Accepted Solutions (0)

Answers (3)

Answers (3)

Avatar

Avatar
Boost 1
Level 1
Vikash_kumar_18
Level 1

Like

1 like

Total Posts

3 posts

Correct Reply

0 solutions
Top badges earned
Boost 1
View profile

Avatar
Boost 1
Level 1
Vikash_kumar_18
Level 1

Like

1 like

Total Posts

3 posts

Correct Reply

0 solutions
Top badges earned
Boost 1
View profile
Vikash_kumar_18
Level 1

31-05-2021

Hi @Vijayalakshmi_S 

 

I am still getting the same error. Please find the details below - 

  • AEM version - 6.5.7 ( Even I tried with 6.5.0)
  • Core Component version - 2.12.0
  • Custom component structure Vikash_kumar_18_0-1622489592181.png

     

  • I even tried with adapters = {SlingTestModel.class}  but no luck.

Avatar

Avatar
Boost 500
MVP
Vijayalakshmi_S
MVP

Likes

505 likes

Total Posts

639 posts

Correct Reply

214 solutions
Top badges earned
Boost 500
Give Back 50
Give Back 5
Ignite 10
Ignite 5
View profile

Avatar
Boost 500
MVP
Vijayalakshmi_S
MVP

Likes

505 likes

Total Posts

639 posts

Correct Reply

214 solutions
Top badges earned
Boost 500
Give Back 50
Give Back 5
Ignite 10
Ignite 5
View profile
Vijayalakshmi_S
MVP

31-05-2021

Hi @Vikash_kumar_18,

I tried reproducing(in AEM 6.5.0, core components version - 2.12.0) what you are trying and I could adapt to ContentFragmentList(CFList) successfully without any issues.

I suggest to cross check the core components version and share below details

  • AEM version and core components version
  • Resource structure of your custom component(inheriting from core CFList) screenshot as authored/available under /content path
  • Complete model class. (Trying using adapters, adapters = {SlingTestModel.class} explicitly, shouldn't be a problem for not having this but just a try)

 

package com.aem.demoproject.core.models;

import com.adobe.cq.wcm.core.components.models.contentfragment.ContentFragmentList;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.Self;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.PostConstruct;

@Model(adaptables = {SlingHttpServletRequest.class, Resource.class}, adapters = {ContentFragmentListModel.class}, resourceType = ContentFragmentListModel.RESOURCE_TYPE, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class ContentFragmentListModel {
    public static final String RESOURCE_TYPE = "demoproject/components/content/cfm";
    private final Logger LOG = LoggerFactory.getLogger(getClass());

    @Self
    private SlingHttpServletRequest slingRequest;

    @PostConstruct
    protected void init() {
        if (slingRequest != null) {
            ContentFragmentList cfmList = slingRequest.adaptTo(ContentFragmentList.class);
            if (cfmList != null) {
                LOG.info("CF Exported Type={}", cfmList.getExportedType()); // displays demoproject/components/content/cfm correctly
                LOG.info("CF List size={}", cfmList.getListItems().size());
            }
        }
    }
}

 

 

Avatar

Avatar
Boost 500
MVP
Vijayalakshmi_S
MVP

Likes

505 likes

Total Posts

639 posts

Correct Reply

214 solutions
Top badges earned
Boost 500
Give Back 50
Give Back 5
Ignite 10
Ignite 5
View profile

Avatar
Boost 500
MVP
Vijayalakshmi_S
MVP

Likes

505 likes

Total Posts

639 posts

Correct Reply

214 solutions
Top badges earned
Boost 500
Give Back 50
Give Back 5
Ignite 10
Ignite 5
View profile
Vijayalakshmi_S
MVP

01-06-2021

Hi @Vikash_kumar_18,

Can you try adding the HTL for your component instead of JSP like below. Can remove the dialog if you are not overriding anything. 

Even if you need to override any fields, for now remove the dialog and lets use the dialog inherited from Core -> author the fields and then try building the project. 

Vijayalakshmi_S_0-1622555765818.png