Page Manager getPage returns NULL for Sling:Alias | Community
Skip to main content
Mahedi_Sabuj
Community Advisor
Community Advisor
August 30, 2023
Solved

Page Manager getPage returns NULL for Sling:Alias

  • August 30, 2023
  • 1 reply
  • 1065 views
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​

 

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

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

1 reply

Peter_Puzanovs
Community Advisor
Peter_PuzanovsCommunity AdvisorAccepted solution
Community Advisor
August 30, 2023

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