This template shows a solution how get some specified nodeDatas out of the first paragraph of each subpage on the top page. And the hole stuff sorted by a specified nodeData. Clear?
I had the following problem:
- parentpage
- childpage1
- childpage2
- childpage3
- childpage4
- ...
Every childpage has only one paragraph with some nodeDatas. Some of these nodeDatas should be shown on the fatherpage, sorted by one of these nodeDatas.
Here's the solution:
<%!
public class CaseInsensitiveComparator
implements java.util.Comparator {
public int compare(Object o1, Object o2) {
Content c1=(Content)o1;
Content c2=(Content)o2;
String s1 = c1.getNodeData("yourNodeDataForSorting").getString().trim();
String s2 = c2.getNodeData("yourNodeDataForSorting").getString().trim();
return s1.compareTo(s2);
}
}
private void collectParagraphs(Collection myChildren, ArrayList childParagraphs) {
for (Iterator myChildrenIterator = myChildren.iterator(); myChildrenIterator.hasNext();) {
Content para = (Content)myChildrenIterator.next();
Iterator paraNodes = para.getChildren().iterator();
Content nodes = (Content)paraNodes.next();
childParagraphs.add(nodes);
}
}
%>
Now use it...
<%
Content actPage = Resource.getActivePage(request);
Collection children = actPage.getChildren();
Iterator childrenIterator = children.iterator();
ArrayList childParagraphs = new ArrayList();
while (childrenIterator.hasNext()) {
Content child = (Content)childrenIterator.next();
Collection myChildren = child.getChildren(ItemType.NT_CONTENTNODE,"nameOfTheParagraph");
collectParagraphs(myChildren,childParagraphs);
}
Collections.sort(childParagraphs, new CaseInsensitiveComparator());
Iterator childParagraphsIterator = childParagraphs.iterator();
while (childParagraphsIterator.hasNext()) {
Content paragraph = (Content)childParagraphsIterator.next();
String someString = paragraph.getNodeData("nodeDataofYourChoice").getString();
}
%>
In its previous incarnation on JspWiki, this page was last edited on Feb 9, 2007 10:11:22 AM by Cbu