Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

Issue while using adaptto of a custom Model that implements a Core interface in a different Sling Model

Avatar

Level 2

Hi

 

Some context I have a SlingModel that implements the Accordion core interface that is mapped to a AEM component lets call it component X
I have another AEM component lets call it Component Y with a corresponding Sling Model that needs some info from the other component (component X).

When I want to adapt in the Sling model of component Y a Resource to the Sling model of Component X with AdaptTo method.
All my "own" fields are mapped correctly  but the accordion variable is null after the adaptTo().
If I open Component X the mapping is correct and I see the correct data.




@Getter
@Model(adaptables = {SlingHttpServletRequest.class, Resource.class},
resourceType = {ExperienceZoneScreenModel.RESOURCE_TYPE},
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class ComponentXModel implements Accordion {

@Self
@Via(type = ResourceSuperType.class)
private Accordion accordion

@ValueMapValue
private String title;


public List<PanelContainerItem> getConfiguredItems() {
return accordion.getChildren();
}
...


}

 

@Model(adaptables = {Resource.class, SlingHttpServletRequest.class})
public class ComponentYModel {

public String getItems() {
....
ComponentXModel cmp = child.adaptTo(ComponentXModel.class);
cmp.getTitle(); // Provide the right title
cmp.getConfiguredItems(); // accordion is null

 

 Does anyone has an idea how to make sure the accordion isn't null?

Thanks

Kind regards

Jeffrey

2 Replies

Avatar

Level 2

The implementation and standalone is working fine.
Problem exist when I want to adapt a resource to the ComponentXModel that my Accordion or in your example the Teaser is null.