In my component's JSP, if I want to reference the current node using currentNode
object, it throws a NullPointerException
and the whole component then throws a ScriptEvaluationException
My component JSP does have the global.jsp
included at the top. I guess currentNode object is created by the global.jsp
Strangely, the component throws these exceptions only in a particular site. It works fine in others.
What possible could be the reason for this ? In what conditions does the currentNode
object be NULL ?
Maybe your component is a synthetic resource? If you have include tag like this:
<cq:include path="mynode" resourceType="myapp/components/somecomponent" />
and mynode
doesn't exist, the included component will be renderer, however you can't referer to the node properties in somecomponent
code.
In this case resource
variable will be a SyntheticResource
and currentNode
will be null
.
Update:
If you don't really need the currentNode
but QueryManager
object (as your comment says), you can use resourceResolver
object to get it:
resourceResolver.adaptTo(Session.class).getWorkspace().getQueryManager()