How to get 'currentPage' in java code when not using activate method | Community
Skip to main content
New Participant
March 16, 2016
Solved

How to get 'currentPage' in java code when not using activate method

  • March 16, 2016
  • 4 replies
  • 2685 views

Hi All,

If we were to retrieve currentPage via activate method[seen below] , we can directly use getCurrentPage() and get it. However, in case I am not using this and also cannot pass getCurrentPage() from the java class where activate method is present , how do I get 'currentPage'?

@Override
    public void activate() throws Exception {}

Any thoughts on this will be helpful.

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 edubey

Activate method is for classes implementing WCMuse interface in sightly.

You can use sling model  or simple resource resolver

Page mycurrentPage = request.getResource().adaptTo(Page.class)

4 replies

askdctmAuthor
New Participant
March 16, 2016

Hi Reply,

Thank you for your reply.It helped.

edubey
New Participant
March 16, 2016

'mycurrentPage' is object of class Page

Now you use any of the specified method available here in https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/com/day/cq/wcm/api/Page.html

Please share the exception or code snippet

askdctmAuthor
New Participant
March 16, 2016

Hi Praveen,

Thanks a lot for your reply.

In my java code, I tried the below :

private static SlingHttpServletRequest slingRequest;

Page mycurrentPage = slingRequest.getResource().adaptTo(Page.class);

but the code is breaking after running this line and not going further.

Not sure what I am doing wrong.

edubey
edubeyAccepted solution
New Participant
March 16, 2016

Activate method is for classes implementing WCMuse interface in sightly.

You can use sling model  or simple resource resolver

Page mycurrentPage = request.getResource().adaptTo(Page.class)