0

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.

SaintLike
  • 9,119
  • 11
  • 39
  • 69
Delmon Young
  • 2,013
  • 5
  • 39
  • 51
  • It's probably means the collections returned is of `Iterable`s and not `Node`. Try `Iterable i` instead of `Node n`. – Bhesh Gurung Jun 03 '13 at 22:50
  • @BheshGurung thanks for the reply but I'm still getting an error except this time it says **cannot loop with element of type iterable with collection of type iterable** – Delmon Young Jun 04 '13 at 01:39
  • @DelmonYoung The code you provided looks OK, I guess it's a different problem. Is it an compiler error or a runtime error? Please post the _exact_ error message. – Thomas Mueller Jun 04 '13 at 06:26

1 Answers1

2

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());
}
%>
Bertrand Delacretaz
  • 6,100
  • 19
  • 24