After some further debugging, I can see the following:
'PageReference.getPage()' calls 'Session.get().getPageManager().getPage()' which then will use 'getRequestAdapter().getPage()'.
This will use 'PersistentRequestAdapter.getPage()' to retrieve the page.
In my sample, PersistentRequestAdapter tries to find the page with 'findPage()' method which will iterate the
'touchedPages' member. The member only contains one entry in my sample, and that is the modal window, not the parent page (referenced page) of the modal window.
So this 'findPage()' call will return null.
As second pass, if returned page was null, getSessionEntry(false) is called and returns a SessionEntry (org.apache.wicket.page.PageStoreManager$SessionEntry) object.
Then 'getPage(id)' on this SessionEntry object is called.
After some checks, the 'sessionCache' member is checked and if that is not null (which is the case), 'findPage(id)' is used to find the page in sessionCache member.
The 'sessionCache' member also only contains the ModalWindow, not the requested page, so again null is returned.
As last option getPageStore() is called and returning an AsynchronousPageStore object.
'getPage()' call is issued on the AsynchronousPageStore object.
The first thing inside this 'getPage()' call is a 'getEntry' call which returns null, so the 'delegate' member (instance of DefaultPageStore) will be used.
'getPage()' is called on 'delegate' member.
In that method, DefaultPageStore member 'pagesCache' (instance of AbstractPageStore) is queryied and will again return null which will result in calling 'getPageData(sessionId, pageId)'.
Now the method 'getData(sessionId, pageId) on 'dataStore' (instance of AsynchronousDataStore) member of AbstractPageStore will be called.
'getEntry(sessionId, id)' will again return null, so 'dataStore.getData(sessionId, id)' is used.
In the DiskDataStore class, 'getData' will use 'getSessionEntry' (returns an object, not null) and then try to load the page with 'sessionEntry.loadPage(id)'.
In 'loadPage' 'getManager().getPageWindow(id)' will return null.
The manger behind 'getManager()' is org.apache.wicket.pageStore.PageWindowManager.
In PageWindowManager object the member 'idToWindowIndex' only contains one entry, and that is the pageId of the ModalWindow, not the parent.
That means, 'getWindowIndex(pageId)' will return -1 because the lookup in idToWindowIndex-Map will return null.
After all of that stuff above, this 'null' value is returned through all the stacks until it reaches my sample code.
The question for me is, why is the initial "parent" page not inside any of those "stores"?