Question

I'm doing a simple CQ include which includes my component.

<cq:include path="banner" resourceType="generic/components/content/banner" />

But instead of using a content dialog I am using a design dialog. I understand the design dialog properties are all stored under /etc/designs/default. So if I try to access the current node object I.E. use:

<%= currentNode.getName() %>

I get a null pointer exception. Why would this be? Isn't there still a node for the design dialogs. Ideally I'm trying to use:

<%= currentNode.getIdentifier() %>

But found out I can't even access the currentNode it just throws a null pointer. Any tips on getting around this, is there another route I need to go to get the currentNode via design dialogs? Any help is greatly appreciated!

Was it helpful?

Solution

The currentNode object contains the resolved JCR Node for the request. Since you are using design dialog, you will be able to access the The design of the addressed resource using the currentDesign object. And in order to access the properties stored in the design dialog you can use the currentStyle object.

currentStyle.get("prop_name");
currentDesign.getId();

Refer to Style api and Design api for information on the methods available.

Since we have the currentStyle object, we can get the path of the style from that and then use the Session object to get the node from that path. After that you can perform all the node operations on it.

Session session = resourceResolver.adaptTo(Session.class);
if(session.nodeExists(currentStyle.getPath())) {
    Node node = session.getNode(currentStyle.getPath());
    node.getIdentifier();
}

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top