Hi,
I am trying to adapt OOTB ContentFragmentList sling model.
I am extending OOTB ContentFragmentList.
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
Solved! Go to Solution.
Views
Replies
Total Likes
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
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());
}
}
}
}
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
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());
}
}
}
}
I am still getting the same error. Please find the details below -
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.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies