Created

Jan 28, 2013

Get child pages based on a template

Posted by Vianney Baron

Sometimes when I need to parse a large CQ website using Java, I want to list the children of a page based on the template. This can be very helpful when creating a carousel displaying featured pages, or working on a search functionnality, as in both cases we need to create a list of pages we want to display back to the user.

There are a few ways to do this: I can use the query builder to create a query based on the cq:template property, but the code can be a bit complex. I could also simply iterate over the children of the page and read the property to create my list, but it's a rather inelegant approach.

So I had a look through the CQ Page API, and found a nice and easy-to-use function for this: listChildren(filter). It fits my requirement perfectly, as I will illustrate here.

Using this function you can leverage an out of the box filter, the PageFilter, as such:

Iterator< Page > it = homePage.listChildren(new PageFilter());

Or create a custom one based on your own requirements. For instance in our case if we want to return the pages using the template named "productpage", we simply have to define the following filter:

class ProductPageFilter implements Filter {

	@Override
	public boolean includes(Object element) {
		Page p = (Page) element;
		return (p.getProperties().get(NameConstants.NN_TEMPLATE, "")
                .equals("/apps/myapp/templates/productpage"));
	}
}

COMMENTS

  • By APK - 10:26 AM on May 31, 2014   Reply
    Many Thanks.
  • By tidung.net - 5:06 AM on Jun 02, 2014   Reply
    Thanks.
    • By cna classes - 6:49 AM on Jun 02, 2014   Reply
      simply iterate over the children of the page and read the property to create my list, but it's a rather inelegant approach.
      • By search - 11:49 AM on Jun 05, 2014   Reply
        Many company exhibitions, like contractors’ businesses, experienced significantly during the excellent economic slowdown of the last few decades.
        • By apk - 11:25 AM on Jun 06, 2014   Reply
          Thanks.
          • By Jasa SEO - 11:31 AM on Jun 08, 2014   Reply
            Many Thanks.
            • By Tattoos - 4:38 PM on Jun 08, 2014   Reply
              Many Thanks.
              • By Energy Performance Certificates - 7:10 AM on Jun 09, 2014   Reply
                Everything from tables to beds to chairs is customizable. Plus, it automatically sends orders to manufacturers when a customer makes a purchase.
                • By step up height - 7:49 AM on Jun 09, 2014   Reply
                  Step up is an effective height increasing formula that increases your height and makes you look fabulous.
                  • By cheap banner design - 10:19 AM on Jun 09, 2014   Reply

                    Step up is an effective height increasing formula that increases your height and makes you look fabulous.
                    • By corporate photographer - 11:22 AM on Jun 09, 2014   Reply
                      Step up is an effective height increasing formula that increases your height and makes you look fabulous.
                      • By Best Cash Back - 6:22 AM on Jun 10, 2014   Reply
                        Step up is an effective height increasing formula that increases your height and makes you look fabulous.
                        • By Best Cash Back - 6:23 AM on Jun 10, 2014   Reply
                          Step up is an effective height increasing formula that increases your height and makes you look fabulous.
                          • By Adica Wilbourn - 6:10 AM on Jun 11, 2014   Reply
                            Step up is an effective height increasing formula that increases your height and makes you look fabulous.
                            • By foto Wedding - 4:07 PM on Jun 11, 2014   Reply
                              i really to say nice tools from adobe. i like it.
                              • By Obat Keputihan - 9:30 AM on Jun 22, 2014   Reply
                                Many Thanks.
                                • By Agen Judi Online - 9:33 AM on Jun 25, 2014   Reply
                                  As we age this careful system changes. Moreover to monitoring moment-to-moment threats such as an beginning car or a decrease banister.
                                  • By http://www.swissphysio.co.uk - 6:59 AM on Jul 02, 2014   Reply
                                    Often it is the surprising lack of way of life of someone near that provides this home; and then the frequency of hospital visits and memorials progressively starts to select up amount, like a drumbeat in the woodlands.
                                    • By cara daftar di bisnis libertagia - 1:36 PM on Jul 02, 2014   Reply
                                      Make sure the connection between each section tightly fits together. By attracting fish, and getting them to strike, you're well on your way to becoming a better fisherman
                                      • By Printer Driver - 7:59 AM on Jul 04, 2014   Reply
                                        This is not the first time im here, great template. I discovered so many interesting things inside your blog especially its discussion.
                                        • By airul - 10:56 AM on Jul 06, 2014   Reply
                                          Thanks.
                                          • By top 10 quotes - 8:07 AM on Jul 07, 2014   Reply
                                            I received the item in a day or so and I was able to complete a photo project I had been working on! It also shuts the feeding ports when they put enough weight on the ring.
                                            • By papas cupcakeria - 7:59 AM on Jul 12, 2014   Reply
                                              PapasCupcakeriaGamePC is a game for kids in which one can handle all the bakery products related to cups. If you want new more games, Please visit site http://papascupcakeriagamepc.com/ ...
                                              • By papas freezeria game pc - 8:04 AM on Jul 12, 2014   Reply
                                                PapasFreezeriaGamePC is a game for human. As one of the biggest free gaming websites, we offer new games every day. If you want more information about top 3 new games, Please visit site http://papasfreezeriagamepc.com/ ...
                                                • By purble place game - 8:10 AM on Jul 12, 2014   Reply
                                                  Funnytowers is a popular card game which requires the skill to make quick decisions in a short time. FunnyTowers Card Games. Please visit website http://purbleplacegame.com/ ...
                                                  • By mughty raju game - 8:13 AM on Jul 12, 2014   Reply
                                                    Steampunk Tower Defense.You only have one tower to work with, and enemies come from both sides. Mighty raju game over. Steampunk Tower Defense. Please visit site for new games http://mightyrajugameover.com/ ...
                                                    • By four wheeler games online - 8:18 AM on Jul 12, 2014   Reply
                                                      There is a minimap showing what comes … Neptune Buggy. Four wheeler game. there are save points in the area. Please visit site for more new four wheeler games http://fourwheelergame.org/ ...
                                                      • By model baju lebaran - 4:50 PM on Jul 12, 2014   Reply
                                                        i really to say nice tools from adobe. i like it.
                                                        • By pure reiki healing mastery book review - 3:51 AM on Jul 13, 2014   Reply
                                                          Pure Reiki Healing Mastery: Owen Coleman Reveals His Step-By-Step Reiki Home Study Course For Becoming A Certified Reiki Master And Healing All Kinds Of Ailments And Disorders With Powerful Self-Treatment Techniques... Written for consumers by a consumer, this fan site includes a fun and informative Pure Reiki Healing Mastery review, ebook FAQ, and PDF download guide that provides an insider's look at the program and answers frequently asked questions about Owen Coleman's unique and highly popular Reiki mastery guide. Please click here site https://www.rebelmouse.com/purereikihealingmasteryreviews/ !
                                                          • By write up - 3:55 AM on Jul 13, 2014   Reply
                                                            The Penguin Method: Samantha Sanderson Reveals Her 3-Step, Drop-Dead-Simple Neurological Reliance Shortcut For Making A Man Love, Adore, And Cherish You... Written for consumers by a consumer, this fan site includes a fun and informative Penguin Method review, ebook FAQ, and PDF download guide that provides an insider's look at the program and answers frequently asked questions about Samantha Sanderson's unique and highly popular relationship guide. Please click here site https://www.rebelmouse.com/penguinmethodreviews/ ...
                                                            • By how can i restore my eyesight - 4:00 AM on Jul 13, 2014   Reply
                                                              Perfect Vision Today: Dr. Sen And Samantha Pearson Reveal A Breakthrough, Step-By-Step System To Achieve 20/20 Vision And Help Cure Myopia, Hyperopia, Presbyopia, And Most Other Visual Problems In As Little As 2 Weeks... Written for consumers by a consumer, this fan site includes a fun and informative Perfect Vision Today review, ebook FAQ, and PDF download guide that provides an insider's look at the program and answers frequently asked questions about Dr. Sen and Samantha Pearson's unique and highly popular guide to better vision. Please click site https://www.rebelmouse.com/perfectvisiontodayreviews/ ...
                                                              • By Getting New Property - 4:02 AM on Jul 13, 2014   Reply
                                                                If you're like most people, purchasing a home is probably one of the biggest investments you'll ever make in your lifetime. If you're considering buying a home, you're likely aware of the complexity of the endeavor. Because of the numerous factors to consider when purchasing a home, it's important to prepare as best you can. Please visit http://ArizonaJumboLoans.com/purchase.php ...
                                                                • By 二元期权策略 - 4:06 AM on Jul 13, 2014   Reply
                                                                  Trading binary optics is now available in China too. See what are the best Chinese binary options brokers. please visit website http://www.binaryoptionschina.org/ !
                                                                  • By ebook directory - 4:10 AM on Jul 13, 2014   Reply
                                                                    Find all your books and eBooks that will you ever need in our eBook library. We have ton's of books on all different categories to choose from. Find your book now! Please visit website http://yourebookdirectory.com/ !
                                                                    • By Innovation - 4:13 AM on Jul 13, 2014   Reply
                                                                      Splash-Free Coffee While On-The-Go, with The SpilliNator. The Spillinator, an innovative and eco-minded product that provides a splash-free drinking experience for coffee and tea lovers on-the-go. The product, invented by actor Al Santos, ensures that there is no leakage from the lid, so you can enjoy your beverage splash-free. Plug The SpilliNator into the sip-hole on most popular beverage lids, and you can pour, sip, and even "suck through the mini sip-tube", all splash-free and on-the-go. Please visit http://www.Sip-Tube.com/ ...
                                                                      • By Dart - 4:20 AM on Jul 13, 2014   Reply
                                                                        Splash-Free Coffee While On-The-Go, with The SpilliNator. The Spillinator, an innovative and eco-minded product that provides a splash-free drinking experience for coffee and tea lovers on-the-go. The product, invented by actor Al Santos, ensures that there is no leakage from the lid, so you can enjoy your beverage splash-free. Plug The SpilliNator into the sip-hole on most popular beverage lids, and you can pour, sip, and even "suck through the mini sip-tube", all splash-free and on-the-go. Please visit http://www.SpilliNator.com/ ...
                                                                        • By venus factor reviews - 8:33 AM on Jul 15, 2014   Reply
                                                                          We were helped by Jerr McKinnon, administrator of coaching and tech support team, and Andrew Richards, item instructor, when using the resources and operating on set ups.
                                                                          • By url opener - 6:24 PM on Jul 15, 2014   Reply
                                                                            This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work...
                                                                            • By Personalised Santa stockings - 6:35 AM on Jul 18, 2014   Reply
                                                                              As the international provide of copper is constantly on the tense up, the market for illegal copper will likely improve,” notices the evaluation.
                                                                              • By Click Here - 12:19 PM on Jul 18, 2014   Reply
                                                                                Technology” advisory categories, in particular, are becoming popular as a way for farm owners to learn about new technological innovation. Associates get together to discuss the technological innovation they have purchased or are looking at.
                                                                                • By duplichecker - 8:00 PM on Jul 18, 2014   Reply
                                                                                  woah! I’m really enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that perfect balance between superb usability and visual appeal. I must say you’ve done a very good job with this.
                                                                                  • By mighty raju games - 3:11 PM on Jul 22, 2014   Reply
                                                                                    nice info i really like it
                                                                                    • By paw patrol games - 3:12 PM on Jul 22, 2014   Reply
                                                                                      very nice website
                                                                                      • By new spongebob games - 3:13 PM on Jul 22, 2014   Reply
                                                                                        happy to read your post i recommended your site.
                                                                                        • By Crystal X Asli - 8:28 PM on Jul 22, 2014   Reply
                                                                                          i really to say nice tools from adobe. i like it.
                                                                                          • By http://www.thirdway.co/ - 7:08 AM on Jul 26, 2014   Reply
                                                                                            Something usual today This is used to promote new products, services, brands of different businesses over the internet. Serve as the main tool of marketing campaigns. click
                                                                                            • By http://parkofficeltd.co.uk/ - 12:29 PM on Jul 28, 2014   Reply
                                                                                              This is used to promote new products, services, brands of different businesses over the internet. Serve as the main tool of marketing campaigns.

                                                                                              ADD A COMMENT