Skip to main content
Level 9
Mar 16, 2016 8:50 AM UTC
Solved

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

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.
edubey
edubeyAccepted solution
Level 10
Mar 16, 2016 10:20 AM UTC

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

edubey
edubeyAccepted solution
Level 10
Mar 16, 2016 10:20 AM UTC

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)

Translate
askdctmAuthor
Level 9
Mar 16, 2016 10:45 AM UTC

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.

Translate
edubey
Level 10
Mar 16, 2016 10:53 AM UTC

'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

Translate
askdctmAuthor
Level 9
Mar 16, 2016 12:19 PM UTC

Hi Reply,

Thank you for your reply.It helped.

Translate