Primefaces Cookbook Second Edition
Total Page:16
File Type:pdf, Size:1020Kb
www.allitebooks.com PrimeFaces Cookbook Second Edition Over 100 practical recipes to learn PrimeFaces 5.x – the most popular JSF component library on the planet Mert Çalışkan Oleg Varaksin BIRMINGHAM - MUMBAI www.allitebooks.com PrimeFaces Cookbook Second Edition Copyright © 2015 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: January 2013 Second edition: May 2015 Production reference: 1250515 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78439-342-7 www.packtpub.com www.allitebooks.com Credits Authors Copy Editors Mert Çalışkan Sarang Chari Oleg Varaksin Sonia Mathur Reviewers Project Coordinator Ramanath Bhongale Harshal Ved Aristides Villarreal Bravo Sebastian D'Agostino Proofreaders Stephen Copestake Commissioning Editor Safis Editing Akram Hussain Indexer Acquisition Editors Mariammal Chettiyar Tushar Gupta Llewellyn Rozario Production Coordinator Conidon Miranda Content Development Editor Ajinkya Paranjape Cover Work Conidon Miranda Technical Editor Humera Shaikh www.allitebooks.com Foreword JavaServer Faces has come a long way since its initial release. This is mostly due to the big ecosystem around it that allows many third-party add-ons to contribute. The first major extension was Facelets that removed the burden of JSP-based views. With 2.0, Facelets became standard, and along with Facelets, many other features, including AJAX, originated from the community. JSF 2.2 followed the same approach and integrated various enhancements, such as HTML5-friendly markup, resource library contracts, and Faces Flows. Considering the current landspace of modern web application development, a server-side component framework such as JSF is still a popular choice among Java developers; this is because JSF is flexible enough to keep up. I started PrimeFaces back in 2009 to provide a new alternative component suite to the JSF ecosystem. As of now, PrimeFaces is the most popular framework and the de facto standard for JSF applications built with Java EE. During this time, the component suite has extended to an over-100-rich suite of components utilizing modern JavaScript and CSS techniques, integrating responsive design, and providing mobile and push modules. PrimeFaces is documented well in PrimeFaces User Guide, and Showcase is considered to be a practical guide in itself. However, there are many cases that can only be seen when doing actual development and are not to be found in the guide or Showcase. PrimeFaces Cookbook, Second Edition, focuses on these cases in a practical way to provide best practices as solutions to common requirements. I've known Mert and Oleg for a long time; both are power users of PrimeFaces and longtime contributors to the framework. Their expertise in PrimeFaces makes this book a great complementary resource when developing applications with PrimeFaces. Çağatay Çivici Founder and Lead Developer of PrimeFaces www.allitebooks.com Foreword I consider it a great blessing to have been associated with the JavaServer Faces technology for such a long time. In the 11 years since JSF 1.0 was released, the little corner of the enterprise software world in which JSF plays has experienced an enormous amount of growth and change, but it is still the world of enterprise software. During this time, I have come to have a deep appreciation of the unique technical and nontechnical requirements of enterprise software. This appreciation has shown me that these two aspects are very closely linked, and any framework that wants to play in the enterprise software space must broadly and deeply address both of them. The fact that there is still demand for the continued evolution of JSF is a testament to the ecosystem behind JSF and also how well it addresses these aspects. One of the key nontechnical requirements of enterprise software is the ability to build projects that have very long service lifetimes. To do this, enterprises need technologies that are good enough to get the job done while having the necessary market backing and support guarantees to be trusted with mission-critical applications. This is where Java lives and thrives, and the Java Community Process (JCP) is the engine to develop Java. There is a tension between the long service lifetime requirement of enterprise software and the constantly evolving state of the art. One element of this evolution is the rise and acceptance of open source software (OSS). When JSF first came out, enterprises looked at open source with a high degree of suspicion. Can we trust it? Will it be there for us throughout the service life for which we need it? Over time, enterprises have come to accept OSS. As the first part of Java to be made open source, JSF has ridden the crest of this trend. This was entirely enabled by the evolution of the JCP with which JSF is developed. Without the opening of the JCP to the ideas of OSS, JSF would have already faded out into nonuse. One could argue that the JCP has helped make OSS for enterprises. www.allitebooks.com The opening of the JCP was also a key enabler for the creation of the JSF component ecosystem, in which PrimeFaces is now the biggest player. I'm very grateful to all of the component libraries in the JSF ecosystem, in particular to PrimeFaces, for taking the core ideas of JSF and building on them to create solutions that can ultimately deliver real business value. Just as PrimeFaces takes the core ideas of JSF, Mert's and Oleg's book takes the core ideas of PrimeFaces and puts them in your hands for quick and easy deployment in your applications. These ideas are presented with frequent How to do it… and How it works… sections, showing first the practice and then the theory of PrimeFaces. With this style of presentation, Mert and Oleg cover the breadth and depth of PrimeFaces, diving down to the core underlying JSF when necessary to drive the point home. I'm confident you'll find the second edition of this book a valuable resource as you develop JSF applications with PrimeFaces. Ed Burns JavaServer Faces Specification Co-lead www.allitebooks.com About the Authors Mert Çalışkan is a software stylist living in Ankara, Turkey. He has more than 10 years of expertise in software development with the architectural design of Enterprise Java web applications. He is an advocate of open source for software projects such as PrimeFaces and has also been a committer and founder of various others. He is the coauthor of the first edition of this book. He is also the coauthor ofBeginning Spring by Wiley Publications. He is the founder of AnkaraJUG, which is the most active JUG in Turkey that has been having monthly meetups for 3 years now. In 2014, he was entitled a Java Champion for his achievements. He is also a Sun Certified Java professional since 2007. He does part-time lecturing at Hacettepe University on enterprise web application architecture and web services. He shares his knowledge at national and international conferences, such as JDays 2015, JavaOne 2013, JDC2010, and JSFDays'08. You can reach Mert via twitter at @mertcal. First, I would like to thank my friend Oleg Varaksin for joining me on this journey. I would also like to thank Çağatay Çivici and Ed Burns for crowning our book with their forewords—without their ideas and inspiration on the JSF ecosystem, this book wouldn't exist. My thanks also go to Ajinkya Paranjape, content development editor; Humera Shaikh, technical editor; and Llewellyn Rozario, acquisition editor, all from Packt Publishing. I would also like to thank our reviewers, Aristides Villarreal Bravo and Sebastian D'Agostino, for the great job they have done in reviewing this book. These people accompanied us during the entire writing process and made the publication of this book possible with their support, suggestions, and reviews. Last but not least, I would like to thank my mother, my father, my Tuğçe, and especially my beloved fiancé, Funda, who gives me her never ending support and enthusiasm. www.allitebooks.com Oleg Varaksin is a senior software engineer living in the Black Forest, Germany. He is a graduate computer scientist who studied informatics at Russian and German universities. His main occupation and "daily bread" in the last 10 years has consisted of building various web applications based on JSP, JSF, CDI, Spring, web services, REST, jQuery, AngularJS, and HTML5. He has a deep understanding of web usability and accessibility. Oleg is an experienced JSF expert and has been working with the PrimeFaces library since its beginning in 2009. He is also a well-known member of the PrimeFaces community and a cocreator of the PrimeFaces Extensions project on additional JSF components for PrimeFaces. Besides the aforementioned technologies, he has worked as a frontend developer with many other web and JavaScript frameworks—Struts, GWT, Prototype, YUI library, and so on. He also implemented an AJAX framework before all the hype about AJAX began.