-2

For example, i have a node ref 29949, it has property like this: enter image description here

so it's positionIndex is 1, this is a customized property. my current nodes is totally unordered, like this:

enter image description here

I wish to compare and sort node into a ascending order by this property-positionIndex, so this node 29949 will stand under 44440, as 44440 has value positionIndex 0. Anyone got any idea how to do that? any code example would be nice.
Cheers

sefirosu
  • 2,558
  • 7
  • 44
  • 69

1 Answers1

0

Firstly, you should grab a session for yourself like (also can be injected)

Context context = MgnlContext.getInstance();
Session session = context.getJcrSession("choiceOfWorkspace");

// Must be the parent of the nodes to be compared.

Node rootNode = session.getRootNode();
NodeIterator iterator = rootNode.getNodes();

// just do an iteration over the iterator

while(iterator.hasNext()){
Node nextNode = iterator.nextNode();
property = nextNode.getProperty("positionIndex");
// do any sorting algorithm here
}

Hope this helps

Cheers,

Ducaz035
  • 3,054
  • 2
  • 25
  • 45