currentNode is null | Community
Skip to main content
Level 4
October 16, 2015
Solved

currentNode is null

  • October 16, 2015
  • 4 replies
  • 2048 views

We are facing issue similar to below thread, but we don't want to use querymanager but rather use the currentNode object

http://stackoverflow.com/questions/18850171/currentnode-object-gives-nullpointerexception

 

In our code we have something like below:

In the control tabControlPG, we are using currentNode.getProperty(). currentNode is always null. So I tried using request.getResource() and even that throws error that getResource() is not availble for HttpServletRequest.

 

Any ideas or pointers are really appreciated.

<%if(currentPage.getName().equalsIgnoreCase("Documents-Publications")) {%>
        <cq:include path="mainContent/tabcontrol" resourceType="/apps/imf/mobile/components/content/customComponents/tabControl"/>
    <%}
    else if(currentPage.getName().equalsIgnoreCase("logistics")) {%>
        <cq:include path="mainContent/tabcontrol" resourceType="/apps/imf/mobile/components/content/customComponents/tabControlPG"/>                
    <%}%>

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 Kunal_Gaba_

I think you are getting currentNode and resource as null in the included script may be because you are setting "path" as virtual as it is pointing to a non existent node in CRX. If that node does not exist then these tags won't inject the resource/node in the request context for processing. Whatever node you want to access in the included JSP, you should set the path to that particular node. 

 

Please see the documentation here - 

https://docs.adobe.com/docs/en/cq/5-6/howto/taglib.html#%3Ccq:include%3E

https://sling.apache.org/documentation/bundles/sling-scripting-jsp-taglib.html

4 replies

Kunal_Gaba_
October 16, 2015

Have you tried using <sling:include> tag for this use case ? 

<sling:include path="mainContent/tabcontrol" resourceType="imf/mobile/components/content/customComponents/tabControlPG" />
Level 4
October 16, 2015

Yes have tried that too

Kunal_Gaba_
Kunal_Gaba_Accepted solution
October 16, 2015

I think you are getting currentNode and resource as null in the included script may be because you are setting "path" as virtual as it is pointing to a non existent node in CRX. If that node does not exist then these tags won't inject the resource/node in the request context for processing. Whatever node you want to access in the included JSP, you should set the path to that particular node. 

 

Please see the documentation here - 

https://docs.adobe.com/docs/en/cq/5-6/howto/taglib.html#%3Ccq:include%3E

https://sling.apache.org/documentation/bundles/sling-scripting-jsp-taglib.html

Level 4
October 16, 2015

Thanks for your tip. Will try and let you know if it works