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 ovariancystmiracle.net - 10:01 AM on Aug 21, 2014   Reply
                        which should remain cautious and other positions should be kept small and manageable. It was interesting to learn that crop is now rated 27% higher.
                      • 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 Did you check it out? - 11:08 AM on Aug 20, 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!
                                                                        • By boondoxxxmx - 11:20 AM on Aug 21, 2014   Reply
                                                                          <p>&nbsp;need a boyfriend, My email id is nosheen_ilyas65@hotmail.com add me and get my mobile number after being my friend, thanks
                                                                      • 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.
                                                                                              • By how to turn a cold woman on - 7:58 PM on Aug 01, 2014   Reply
                                                                                                Make Women Want You System: Jason Capital Reveals His 3-Step Formula To Create Consistent, Predictable, and INTENSE Attraction With Any Woman You Want. Written for consumers by a consumer, this site includes a fun and informative Make Women Want You review and buyers guide that provides an insider's look at the program and answers frequently asked questions about Jason Capital's unique and highly popular system for helping you meet, attract, and seduce hot women. Please click here https://www.rebelmouse.com/makewomenwantyoureview/ ...
                                                                                                • By boost your bust breast massage - 8:03 PM on Aug 01, 2014   Reply
                                                                                                  Boost Your Bust: Get The Sexy Curves That Drive Men Wild By Using The "Magic Formula" To Natural Breast Enlargement. This site is a leading resource for information about the Jenny Bolton Boost Your Bust PDF book and breast enhancement system that teaches you how to get bigger breasts naturally right from home. Includes a collection of Jenny Bolton Boost Your Bust reviews, PDF ebook download information, and tips for increasing your cup size from around the web. Please click here site https://www.rebelmouse.com/boostyourbustjennybolton/ ...
                                                                                                  • Girlfriend Activation System: Christian H. Reveals How To Get A Girlfriend Using A Step-By-Step Method That Activates Her Obsession Story And Compels Her To Chase You This site includes a Girlfriend Activation System review and buyers guide that provides an insider's look at the program and answers frequently asked questions about Christian's unique and highly popular system for getting the girl you really want to be your girlfriend. Learn everything you need to know about the program so you can decide if the Girlfriend Activation System is the right choice for you before you buy it. Please visit my site for more info: https://www.rebelmouse.com/girlfriendactivationreview/ ...
                                                                                                    • By Planetwin365 Poker - 8:18 PM on Aug 01, 2014   Reply
                                                                                                      Il nostro portale è il migliore sul web che recensisce il famosissimo bookmakers online Planetwin365, ed informiamo ai nostri lettori tutte le informazioni sui, contatti, bonus, società ed tutto ciò che riguarda il famosissimo bookmakers Austriaco "Planetwin365" definito come il sito amico degli italiani. Inoltre sul nostro sito web troverete il link per accedere dall'Italia sempre aggiornato, senza avere mai più problemi per accedere. Please visit my site http://www.scommesse-online.net/ ...
                                                                                                      • By check these guys out - 8:23 PM on Aug 01, 2014   Reply
                                                                                                        trade binary options now and profit easy
                                                                                                        • By http://www.covercity.net/users/tunnop - 8:27 PM on Aug 01, 2014   Reply
                                                                                                          I am surprised by your professionalism, you have talent and you have to develop it. How can you be an even better view is http://www.covercity.net/users/tunnop if you are interested then tell me and I'll give you a free account at covercity and you download everything for free.
                                                                                                          • By Clearwater Real Estate - 9:28 AM on Aug 07, 2014   Reply
                                                                                                            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 t
                                                                                                            • By how to get more instagram followers - 2:01 PM on Aug 16, 2014   Reply
                                                                                                              Buy real instagram followers and instagram likes at cheapest price from just $1.5 . We are the best in the business for the past 2 years. What you are waiting for just visit our site http://theadbash.com and buy instagram followers & likes and boost your profile .
                                                                                                              • By girlfriendactivationsystemreviews.com - 2:02 PM on Aug 16, 2014   Reply
                                                                                                                Girlfriend Activation System Review: web's #1 girlfriend system (GFAS V2) by Christian H. teaches you how to get a girlfriend by activating her obsession story. For more info, visit our website http://girlfriendactivationsystemreviews.com/ ...
                                                                                                                • By HDFC NetBanking Login - 2:05 PM on Aug 16, 2014   Reply
                                                                                                                  Secure Login | Access the HDFC NetBanking login here. Secure user login to HDFC NetBanking. To access the secure area for HDFC NetBanking you must proceed to the login page. For more info, visit my website http://hdfcnetbanking.loginq.com/ ...
                                                                                                                  • By girlfriendactivationsystemreviews.com - 2:08 PM on Aug 16, 2014   Reply
                                                                                                                    Girlfriend Activation System Review: web's #1 girlfriend system (GFAS V2) by Christian H. teaches you how to get a girlfriend by activating her obsession story. For more info, visit our website http://girlfriendactivationsystemreviews.com/ ...
                                                                                                                    • By High Pr blog comments - 10:48 AM on Aug 18, 2014   Reply
                                                                                                                      Perfection head office to help renew the battery power for eight time in the evening after specialists generate them 120 kilometers during the day.

                                                                                                                      • By High Pr blog comments - 10:49 AM on Aug 18, 2014   Reply
                                                                                                                        hіs iѕ а great article thаnkѕ fоr sharing thіѕ i
                                                                                                                        • 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
                                                                                                                          • the children of a page based on the template. This can be very helpful when creating a carousel displaying featur

                                                                                                                            ADD A COMMENT