Question

I've got a pretty basic snippet of code that gets the currentNode of an object and looks through to get it's child nodes. Except for some reason this isn't working and I can't figure out why. getChildNodes() is suppose to return an iterable list of children but all I'm getting is a: "Cannot loop with element of type node with collection of type Iterable

Node currentNode = resource.adaptTo(Node.class)
for (Node n : JcrUtils.getChildNodes(currentNode)){
//do something
}

Any ideas? Thanks for the help.

Was it helpful?

Solution

The following Sling JSP script works for me. The sling:defineObjects tag provides currentNode.

<%@page import="javax.jcr.Node,org.apache.jackrabbit.commons.JcrUtils" session="false"%>
<%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0"%>
<sling:defineObjects/>
<%
for (Node n : JcrUtils.getChildNodes(currentNode)){
  out.println(n.getPath());
}
%>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top