Hi All,
i want to read the count of the components which is repeated component.
Example: RootContentNode/jcr:content/pageContent/header/
/header_1
/header_2
The above example the header component repeated as three times, so i want to get the count as 3.
thanks in advance
michael
Could you please help me out.
Solved! Go to Solution.
Views
Replies
Total Likes
You will have to write a custom logic (Purely Java) using JCR API to get the count of the repeated component
Logic 1: If you want to find the components which is repeated, then get the list of component names from apps and write a search query for each of the component name. Based on the result set see if you see multiple results for a same node.
Logic 2: Under /content loop through each of the node under jcr:content and see if the node *like* current node name exists or not. If yes, then that component is repeated in a given page node.
Views
Replies
Total Likes
Hi Michael,
Try this.
long count = 0;
QueryManager qm;
try {
String compPath = "project/components/header";//example : project/components/header
String searchQuery = "SELECT * FROM [nt:unstructured] AS s WHERE ISDESCENDANTNODE(["+currentPage.getPath()+"/jcr:content"+"]) and [sling:resourceType]='"+compPath+"'";
qm = resourceResolver.adaptTo(Session.class).getWorkspace().getQueryManager();
Query query = qm.createQuery(searchQuery, Query.JCR_SQL2);
QueryResult result = query.execute();
count = result.getRows().getSize();//component count
} catch (RepositoryException e) {
}
Views
Replies
Total Likes
You will have to write a custom logic (Purely Java) using JCR API to get the count of the repeated component
Logic 1: If you want to find the components which is repeated, then get the list of component names from apps and write a search query for each of the component name. Based on the result set see if you see multiple results for a same node.
Logic 2: Under /content loop through each of the node under jcr:content and see if the node *like* current node name exists or not. If yes, then that component is repeated in a given page node.
Views
Replies
Total Likes
Adding to Lokesh's comment. Please find below the community articles for using JCR API
Link:- https://helpx.adobe.com/experience-manager/using/querying-experience-manager-data-using1.html (Querying Adobe Experience Manager Data using the JCR API)
Link:- https://helpx.adobe.com/experience-manager/using/programmatically-accessing-cq-content-using.html (Programmatically Accessing Adobe CQ Content using the JCR API)
Thanks and Regards
Kautuk Sahnia
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies