Expand my Community achievements bar.

Join us in celebrating the outstanding achievement of our AEM Community Member of the Year!
SOLVED

Page Manager getPage returns NULL for Sling:Alias

Avatar

Community Advisor
Let's assume we have a servlet (resource type binding) that retrieves a list of pages. Within the page properties, we've assigned a sling:alias, let's say "gb" to the uk node. While the servlet works as expected when accessed through "/content/.../uk," when attempting to access it via "/gb," the PageManager.getPage function returns null. 

 

final ResourceResolver resourceResolver = request.getResourceResolver();
final PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
final Page page = pageManager.getPage(rootPagePath); // Retuens NULL for sling:alias​

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi Mahedi,

 

PageManager expects a fully qualified path.

 

Since you already have ResourceResolver and Request as well as absolute path, add an extra invocation to retrieve the actual absolute path by calling:


@Mahedi_Sabuj wrote:
Let's assume we have a servlet (resource type binding) that retrieves a list of pages. Within the page properties, we've assigned a sling:alias, let's say "gb" to the uk node. While the servlet works as expected when accessed through "/content/.../uk," when attempting to access it via "/gb," the PageManager.getPage function returns null. 

 

final ResourceResolver resourceResolver = request.getResourceResolver();
final PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
final Page page = pageManager.getPage(rootPagePath); // Retuens NULL for sling:alias​

 


final Resource res = resourceResolver.resolve(request, rootPagePath);

 

Then path the complete path to get your Page from PageManager.

 

Hope it helps!

 

Regards,

Peter

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Hi Mahedi,

 

PageManager expects a fully qualified path.

 

Since you already have ResourceResolver and Request as well as absolute path, add an extra invocation to retrieve the actual absolute path by calling:


@Mahedi_Sabuj wrote:
Let's assume we have a servlet (resource type binding) that retrieves a list of pages. Within the page properties, we've assigned a sling:alias, let's say "gb" to the uk node. While the servlet works as expected when accessed through "/content/.../uk," when attempting to access it via "/gb," the PageManager.getPage function returns null. 

 

final ResourceResolver resourceResolver = request.getResourceResolver();
final PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
final Page page = pageManager.getPage(rootPagePath); // Retuens NULL for sling:alias​

 


final Resource res = resourceResolver.resolve(request, rootPagePath);

 

Then path the complete path to get your Page from PageManager.

 

Hope it helps!

 

Regards,

Peter