AEM Page adapt to experience fragment in test

Avatar

Avatar
Level 1
JiaJian213
Level 1

Likes

0 likes

Total Posts

3 posts

Correct reply

0 solutions
View profile

Avatar
Level 1
JiaJian213
Level 1

Likes

0 likes

Total Posts

3 posts

Correct reply

0 solutions
View profile
JiaJian213
Level 1

06-11-2020

Hi, This problem, I've been bugging me around a bit. Whenever I am adapt to ExperienceFragmentVariation, it returns me a NULL. Anyone have some insight on this?

Screen Shot 2020-11-06 at 5.52.11 PM.png

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Ignite 1
MVP
SureshDhulipudi
MVP

Likes

163 likes

Total Posts

174 posts

Correct reply

49 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back 10
Give Back
View profile

Avatar
Ignite 1
MVP
SureshDhulipudi
MVP

Likes

163 likes

Total Posts

174 posts

Correct reply

49 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back 10
Give Back
View profile
SureshDhulipudi
MVP

07-11-2020

 

Is your page resource is Experience Fragment Page?

can you try like get Experience Fragment resource page and then get the variations list of that page resource and then adapto

 

ResourceResolver resourceResolver;
resourceResolver = resourceResolverFactory.getServiceResourceResolver(<<<inputparam>>>);
Resource res=resourceResolver.getResource(<<<<<<Page Path / Resource Path>>>>);
Page page=res.adaptTo(Page.class);
ExperienceFragmentsService expService=experienceFragmentsServiceFactory.getExperienceFragmentsService(<<<resourceResolver>>>);
            /// check if the page is Experience Fragment type or content Fragment type
if(page.getContentResource().isResourceType("cq/experience-fragments/components/experiencefragment")){ 
Iterator<Page> fragmentVariation=page.listChildren(new PageFilter(),false);
while(fragmentVariation.hasNext()){
Page fragmentPage=fragmentVariation.next();
if(null!=fragmentPage){
 ExperienceFragmentVariation fragmentVariation = fragmentPage.adaptTo(ExperienceFragmentVariation.class);
      if (null!=fragmentVariation)  
              <<< LOGIC to implement>>>
      else 
           logger.warn("The page at path cannot be adapted to an experience fragment variation");
}
 

Answers (1)

Answers (1)

Avatar

Avatar
Establish
MVP
BrianKasingli
MVP

Likes

647 likes

Total Posts

607 posts

Correct reply

239 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Establish
MVP
BrianKasingli
MVP

Likes

647 likes

Total Posts

607 posts

Correct reply

239 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
BrianKasingli
MVP

08-11-2020

@JiaJian213,

Can you please share the error logs?