When/Why my component's 'currentNode' default object is returning null in jsp?
Hi,
I have created a page content component which is explained in the excercise and created the hierarchy like below
- training
-componenets
-page
contentpage (cq:Component)
contentpage.jsp
head.jsp
body.jsp
header.jsp
content.jsp
footer.jsp
title (cq:Component)
title.jsp
I also created a title component under training/componenets/page called 'title' its primary function to get the page title dynamically wherever it calls
and the code title.jsp is given below. This is being called under content.jsp attached its code also below
<%@include file="/libs/foundation/global.jsp"%>
<%@page session="false" %>
<%= properties.get("title",currentPage.getTitle()) %>
<%
if(currentNode == null)
out.println("currentNode is null");
else
out.println("currentNode is not null");
%>
i am pasting below the contentpage.jsp for our discussion
<%@include file="/libs/foundation/global.jsp"%>
<%@page session="false" %>
<html>
<cq:include script="head.jsp" />
<cq:include script="body.jsp" />
<cq:include script="/libs/wcm/core/components/init/init.jsp"/>
Title: <%= currentNode.getProperty("jcr:title").getString() %><br />
Name: <%= currentNode.getName() %><br />
Path: <%= currentNode.getPath() %><br />
Depth: <%= currentNode.getDepth() %><br />
</html>
body.jsp
<%@include file="/libs/foundation/global.jsp" %>
<body>
<div class="bg">
<cq:include script="header.jsp"/>
<cq:include script="content.jsp"/>
<cq:include script="footer.jsp"/>
</div>
</body>
header.jsp
<%@include file="/libs/foundation/global.jsp" %>
<div class="header">
<div class="container_16">
<div class="grid_8">
<div> logo </div>
</div>
<div class="grid_8">
<div class="search_area">
<div> userinfo </div>
<div> toptoolbar </div>
<div> search </div>
<div class="clear"></div>
</div>
</div>
<div> <cq:include path="topnav" resourceType="training/components/topnav" /> </div>
</div>
</div>
head.jsp
<%@include file="/libs/foundation/global.jsp"%>
<head>
<title><%= currentPage.getTitle() == null ? currentPage.getName() :currentPage.getTitle() %> </title>
</head>
footer.jsp
<%@include file="/libs/foundation/global.jsp" %>
<div class="footer container_16">
<div class="grid_6">
<div> toolbar </div>
</div>
<div class="clear"></div>
</div>
content.jsp
<%@include file="/libs/foundation/global.jsp" %>
<div class="container_16">
<div class="grid_16">
<div> breadcrumb </div>
<!--div> title </div-->
<cq:include path="title_node" resourceType="training/components/page/title" />
</div>
<div class="grid_12 body_container">
<div> par </div>
</div>
<div class="grid_4 right_container">
<div> newslist </div>
<div> rightpar </div>
</div>
<div class="clear"></div>
</div>
The project structure is attached in the screenshot for reference.
Question.
1. contentpage.jsp is printing the property using 'currentNode'. But title.jsp is returning null why?
2. Both 'contentpage' and 'title' are of type cq:Component, apart from that i didn't find any difference except that am seeing sling:resourceSuperType = foundation/components/page property is configured for 'contentpage' componenet. Does it make any difference here?