.getChildren() contain current page although its not a children of the reference?

Hello,

im currently trying to build an “as basic as it gets” version of the documentTree macro in velocity that creates an simple bullet list with XWiki links so that I can use this in the Navigation Menu bar.

Im quite successfull, howerver there is one thing I absolutely don’t understand: The current page that where the macro is run from is always listed as a children, even when it is definetly not a children from the reference?!

Here is my code, it is running as velocity script in my current page “Testarea.WebHome”

{{velocity}}
#set($parentReference = $services.model.createDocumentReference('', 'MyTopPageIWantToListInTheNavigationMenu', ''))
#set($objClass = $itemDocument.getObject('XWiki.RedirectClass'))
#set($parentDocument  = $xwiki.getDocument($parentReference))
(% id="clientList" class="doOddEven filterable grid sortable" %)
(% class="sortHeader" %)
#foreach ($child in $sorttool.sort($parentDocument.getChildren()))
  #set ($childDoc = $xwiki.getDocument($child))
  #set ($childDocTitle = $childDoc.plainTitle)
##  #if ($xwiki.hasAccessLevel('view', $services.user.currentUserReference , "$childDoc.WebHome") == true && !$objClass)
  #if ($childDoc)
    * [[${childDocTitle}>>doc:${child}]]
    #foreach ($SUBchild in $sorttool.sort($childDoc.getChildren()))
      #set ($SUBchildDoc = $xwiki.getDocument($SUBchild))
      #set ($SUBchildDocTitle = $SUBchildDoc.plainTitle)
##      #if ($xwiki.hasAccessLevel('view', $services.user.currentUserReference , "$SUBchildDoc.WebHome") == true && !$objClass)
      #if ($SUBchildDoc)
        ** [[${SUBchildDocTitle}>>doc:${SUBchild}]]
      #end
    #end
  #end
#end
{{/velocity}}

Now this script lists everything correctly as I want. BUT the first ever entry, is always the Testarea itself ?!

Im completely confused and appreciate any help.
Best regards,
Tom

Also has anybody an more easy way? Maybe to get the documentTree to be simply create an bullet list with links so that it can be used in the Navigation Menu of the Menu Application?

OK I found out how to reproduce it and it confuses me even more.

This problem only occurs when I create a new page while standing in the Page MyTopPageIWantToListInTheNavigationMenu and then while creating the page change the destination where the page should be created (for example directly below root or somewhere else).

That new created page even though it is created somewhere else still somehow regarded as a child of the page where you clicked “create”?!

If I create a new page while being somewhere else than MyTopPageIWantToListInTheNavigationMenu and move it below the page MyTopPageIWantToListInTheNavigationMenu it will get sorted as expected.
If I create a page while being in MyTopPageIWantToListInTheNavigationMenu and change the location to somewhere else it gets shown at the very top in the mini macro.
If I then rename that page it gets no longer shown by my mini macro.

So apparently an rename / move “cleans up” the weirdness.

Is this a bug or is this an intentional feature?