Hi All,
I am invoking a tag lib with slingRequest object in which i have the following code
import com.day.cq.wcm.api.Page; public class Temp extends SimpleTagSupport{ public static String getValue(SlingHttpServletRequest request){ LOG.info("Resource Path is {}",request.getResource()); Page page = request.getResource().adaptTo(Page.class); LOG.info("Page is {}",page); } }
The resource path from the log is /content/my-cq-page/jcr:content and the page object that i got is null. I am not sure why it is null. Is there a better way to extract a page object from a sling request?
Can someone help me on this?
Thanks,
Jai.
Solved! Go to Solution.
Views
Replies
Total Likes
Views
Replies
Total Likes
It returns null because the path " /content/my-cq-page/jcr:content" represent cq:PageContent object and not the "cq:Page" object.
Views
Replies
Total Likes
Views
Replies
Total Likes
It is working!!!
Managed to accomplish it like this
ResourceResolver resourceResolver = request.getResourceResolver(); Resource resource = request.getResource(); PageManager pageManager = resourceResolver.adaptTo(PageManager.class); Page page = pageManager.getContainingPage(resource);
Thanks kunal and edubey for your reply.
Views
Likes
Replies