Not able to access jcr:content properties of currentPage. | Community
Skip to main content
Level 3
June 29, 2021
Solved

Not able to access jcr:content properties of currentPage.

  • June 29, 2021
  • 3 replies
  • 3212 views

Hi Community,

I have written this basic code to access jcr:content properties of my current page specifically cq:tags property but it is not working.

 

public Void activate throws exception{

rootpage=getCurrentPage;

Resource res = getResourceResolver.getResource(rootpage.getPath);

         ValueMap pageProperties = res .getValueMap();

         tag= (String) properties.get("cq:tags", "Default value");

}

 

When I'm using getter method to access the cq:tags property it is showing only Default Value and not the real value of cq:tags even though I can see cq:tags property inside jcr:content in pages.

Please help. 

Is there any other way of achieving the same task?

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 Ritesh_Mittal

Hi @shagunmalik ,

 

It is because "rootpage.getPath" is just path to a page (for example /content/mywebsite/en/mypage) and it is not ending with "jcr:content" node, whereas the properties you are looking for are stored on jcr:content node. So you have to add jcr:content before making resource ((for example /content/mywebsite/en/mypage/jcr:content) ).

 

Resource res = getResourceResolver.getResource(rootpage.getPath + "/jcr:content/");

 

The best way is to enable debugger in your favorite IDE (eclipse for example) and inspect on run time. That way you will find it more easy while development.

 

hope it helps!

3 replies

Ritesh_Mittal
Community Advisor and Adobe Champion
Ritesh_MittalCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
June 29, 2021

Hi @shagunmalik ,

 

It is because "rootpage.getPath" is just path to a page (for example /content/mywebsite/en/mypage) and it is not ending with "jcr:content" node, whereas the properties you are looking for are stored on jcr:content node. So you have to add jcr:content before making resource ((for example /content/mywebsite/en/mypage/jcr:content) ).

 

Resource res = getResourceResolver.getResource(rootpage.getPath + "/jcr:content/");

 

The best way is to enable debugger in your favorite IDE (eclipse for example) and inspect on run time. That way you will find it more easy while development.

 

hope it helps!

Level 3
June 29, 2021

Hey @ritesh_mittal  I'm getting logger to debug and when I see Error logs I found error "AEM failed to activate Use class". How to resolve it?

I have made the changes that you suggested.

Dipti_Chauhan
Community Advisor
Community Advisor
June 29, 2021

Hi @shagunmalik 

  There are multiple things you need to validate here:

  • pageProperties  is your valueMap object but you are using "properties" to get cq:tags. Please check.
  • If you already have page object why you need to convert it to resource? you can get properties from page itself.
  • If you want to use this code snippet than you can use what @ritesh_mittal suggested or you can use below mentioned code snippet to get jcr:contentfinal Resource resource = pageResource.getChild("jcr:content");
    if (resource != null) {
    ValueMap map = resource.getValueMap();

Thanks

Dipti

GnanendraPonnala
Level 2
June 29, 2021