5 Replies Latest reply on Jun 18, 2012 7:32 AM by stewa52

    How to get leaf Pages?

    stewa52

      How do I get a list of all leaf Pages below a given path?

        • 1. Re: How to get leaf Pages?
          orotas Level 4

          In what context are  you asking the question? If you want the list to show up on a page the out of the box list component will do that for you.

           

          In code you can use the pageManager object to get the Page object for the path in question, and then you can use the listChildren method to get a list of the child pages.

           

          There are other answers if you are looking to get the list in JavaScript or search based contexts.

          • 2. Re: How to get leaf Pages?
            stewa52 Level 1

            Won't listChildren only get me the direct children of a node?  I wanted to get all leaf children below a node.

             

             

            Example)

            I want to get all number pages below using the parent as the path.  I could probably right a recursive method using listChildren to get all leaf nodes, but I was wondering if there is an API method or a more elegate way to do this.  Another solution could be to use the TagManager and have all the leave nodes tagged with a specific tag.

            parent

                 -a

                      -1

                      -2

                      -3

                 -b

                      -1

                      -2

                      -3

            • 3. Re: How to get leaf Pages?
              orotas Level 4

              Rather than using tags it would be simpler to use the Query Builder Java API

               

              Map<String, String> map = new HashMap<String, String>();

              map.put("path", "/path/that/you/care/about");

              map.put("type", "cq:Page");

               

              Query query = builder.createQuery(PredicateGroup.create(map), session);

               

              SearchResult result = query.getResult();

               

              //iterate over the hits and do whatever you need.

               

              I don't know how that would compare from a peformance perspective to a recursively iterating over the pages in a path, but it would be easier than using the tag manager.

              • 4. Re: How to get leaf Pages?
                stewa52 Level 1

                Will this also get the non-leaf nodes (a, b)? 

                • 5. Re: How to get leaf Pages?
                  stewa52 Level 1

                  Hello orotas,

                   

                  Will this query also get non leaf nodes?  Is there a way to specify in the query to only get pages without child pages?


                  thanks,

                   

                  awstewar1