Issue while using adaptto of a custom Model that implements a Core interface in a different Sling Model | Community
Skip to main content
JeffreyVSpringbok
Level 2
January 31, 2024

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

  • January 31, 2024
  • 1 reply
  • 622 views

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

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

1 reply

arunpatidar
Community Advisor
Community Advisor
January 31, 2024
JeffreyVSpringbok
Level 2
February 1, 2024

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.