Fetching jcr:content properties
Hello Community - I am using this model for the component to read the properties and perform some action, it is working and I am able to read the properties of the component.
@Model(adaptables = { Resource.class, SlingHttpServletRequest.class })
public class Test {
@PostConstruct
public void init() {
Node curNode = this.request.getResource().adaptTo(Node.class);
try {
if (curNode.hasProperty("compId")) {
String compId = curNode.getProperty("compId").getString();
}
}
}
}
I would like to read some additional properties which are required and only available in jcr:content(cq:PageContent) node of the page. I was trying to read using the below but it is not working. Am I doing anything wrong here? Can someone advise on this?
ResourceResolver resourceResolver=request.getResourceResolver();
Resource resource=resourceResolver.getResource("/content/testsite/en/homepage/jcr:content");
ValueMap properties = resource.adaptTo(ValueMap.class);
String title = properties.get("jcr:title", (String) null);
