1 Reply Latest reply on Jun 12, 2012 6:53 PM by adamyocum

    how to get the list of component?


          How to get the list of component through java API in Adobe CQ5?

        • 1. Re: how to get the list of component?

          There are probably more than a few ways, but here is a little component .jsp code that uses the jcr query api to pull out all the components and list them on a page.  If I know CQ, there might be a way to ask for a list of components another way though, maybe through another API, or possibly a .json url, I might remember reading something about that, somewhere, lol, but this at least gets you the list in a somewhat simple way.


          Code Example:


          <%@include file="/apps/psul/components/global.jsp"%>
          <%@ page import="javax.jcr.*,
             // Login to create an anonymous session on the default workspace
             Session session = resourceResolver.adaptTo(Session.class);
                 //Declare a query for all the components in the system
                 String SQL = "select * from cq:Component";
          //side note: if you want just the components in your site area, then make the query more like below... 
          //  SQL = "select * from cq:Component where jcr:path like '/apps/yoursitename/%'";
                 QueryManager qm = session.getWorkspace().getQueryManager();
                 Query query = qm.createQuery(SQL, Query.SQL);
                 QueryResult result = query.execute();
                 NodeIterator nodes = result.getNodes();
                 while (nodes.hasNext()) {
                     Node node = (Node)nodes.next();
                          <p><%=node.getName() %> (<b><%=node.getPath() %></b>)</p>
          <%     } %>