In AEM, I'm working with Query Builder to fetch all the components of a page in the same order as they are in the page. Nothing fancy.
In other words, the same order as they are shown in the jcr:content.
However, the query is returning all nodes in a scrambled way.
This is the query that I'm using:
type.type = cq:node
orderby = @jcr:content
I have also tried to use NodeIterator. but, my page is not certain of the number of childs.
Having all the components sequentially as a list will do.
Is there a way? Please address this.
I am trying to do something similar from within CRXDE Lite; I am trying to retrieve all (unique) components used within 1 site. But I am struggling with this...
The order in which QueryBuilder returns results cannot be guaranteed but you could use the path of one of those components to resolve the parent via a ResourceResolver and call listChildren() (Resource (Apache Sling (Builder) 6 API)) on that parent resource. This should give you back the component instances in the proper order. If what QueryBuilder returns is component instances from all over your site and not just a collection of siblings, you could build a list of unique parent Resources from your query results and just do what I've mentioned above for each of those parent Resources via a loop or stream.
To get a listing of all the unique components used through a site you can use the component lister that comes with ACS Commons (or it's in a service pack - I don't recall). If you need to do it programmatically, then you can use QueryBuilder to query for all cq:Component instances starting at a root path you specify (the root of your site). If you only want a listing of each type of component that is used on your site and you don't care about a particular component being used more than once (i.e. you just want to know that it WAS used and not necessarily how many times) then you can squash your QueryBuilder results by iterating through them and adding new cq:Component instances to a new List<Resource>.