Tuesday, July 26, 2011

jcr:content and

these are commonly used in jsp after <cq:defineObjects/> and <sling:defineObjects/>:

  • resource
  • currentNode
  • currentPage
resource.getPath()  is the node that has sling:resourceType  (usually /foo/bar/jcr:content)

currentNode.getPath() is the node that has sling:resourceType

currentPage.getPath() is actual Page (usually, /foo/bar).

so, if you have something like:
<%
iter = queryResult.getNodes(); //returns  cq:Page nodes
while (iter.hasNext()) {
    sling.include(iter.nextNode().getPath());// resource of the script included will be jcr:content
}
%>

However, if you specify resourceType for include, 
For example,  SlingScriptHelper
with RequestDispatcherOptions.setForceResourceType()  or,  <sling:include resourceType="..."/>, the included script (handler)'s  resource is NOT jcr:content but the resource itself. (Not  /foo/bar/jcr:content,  but /foo/bar..  where included resource was /foo/bar).

Okay this is hairy.

Let's work an example. 

Client request was:

GET /x/y.html


/x/y's resourceType (handler) is /apps/a/handler.
In /apps/a/handler/handler.jsp,  you include /foo/bar (a cq:Page).  /foo/bar's resourceType is /apps/b/handler.

You include:
  1. <sling:include path="/foo/bar.html"/>
    1. then /apps/b/handler will be used.
    2. resource is /foo/bar/jcr:content
    3. currentNode is /foo/bar/jcr:content
    4. currentPage is /foo/bar
  2. <sling:include path="/foo/bar" resourceType="c/handler'/>
    1. /apps/c/handler is used
    2. resource is /foo/bar
    3. currentNode is /foo/bar
    4. currentPage is /x/y




No comments:

Post a Comment