Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Get all the components of a page in sequence

Anonymous
Not applicable

Hi,

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:

path=/content/cacom/en_us/qa-itc-test-data----jan-27-2016/solution-expanding-list-test-data/jcr:content/contentinfo

type.type = cq:node

orderby = @jcr:content

p.limit=-1

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.

Thanks,

Priya

0 Replies
tom_borst
Level 1
Level 1

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... 

joshdboyle
Level 1
Level 1

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.

joshdboyle
Level 1
Level 1

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>.