IN ACTION Covers Portlet 2.0, Spring 3.0 Portlet MVC, WSRP 2.0, Portlet Bridges, Ajax, Comet, Liferay, GateIn, Spring JDBC and Hibernate Ashish Sarin M A N N I N G BEST PRACTICES INSIDE THE BOOK Best Practice Page number Section Use user attributes to obtain user information in portals 96 3.2.2 Handle portal server–specific requests using PortalContext 99 3.2.4 Encode URLs to resources 102 3.3.1 Choose appropriate portlet lifecycle phase to process an action 107 3.3.4 Add custom JavaScript and CSS files to a portal page using MARKUP_HEAD element 108 3.3.5 Choose appropriate PortletSession scope for storing objects 116 3.4.4 Evaluate use of container-runtime options 123 3.7.1 Use actionScopedRequestAttributes along with PortletSession 127 3.7.1 Choose wisely when to use servletDefaultSessionScope container-runtime option 128 3.7.2 Consider performance impact of container-runtime options 130 3.7.5 Choose appropriate validation token in validation-based caching strategy 140 4.1.2 Localize portlet content 141 4.2 Use Apache Commons FileUpload for uploading files 156 4.6.1 Override portlet request and response objects’ functionality using wrapper classes 158 4.6.2 Design portable portlets 161 4.7 Simplify portlet URL creation using portlet tag library tags 213 6.3 (Continued on inside back cover) Portlets in Action Portlets in Action ASHISH SARIN MANNING SHELTER ISLAND For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 261 Shelter Island, NY 11964 Email: [email protected] ©2012 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. Manning Publications Co. Development editors: Emily Macel, Jeff Bleiel 20 Baldwin Road Copyeditor: Andy Carroll PO Box 261 Proofreader: Katie Tennant Shelter Island, NY 11964 Typesetter: Dennis Dalinnik Cover designer: Marija Tudor ISBN: 9781935182542 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – MAL – 17 16 15 14 13 12 11 brief contents PART 1 GETTING STARTED WITH PORTLET DEVELOPMENT..........1 1 ■ Introducing portals and portlets 3 2 ■ The portlet lifecycle 48 3 ■ Portlet 2.0 API—portlet objects and container-runtime options 86 4 ■ Portlet 2.0 API—caching, security, and localization 132 5 ■ Building your own portal 167 6 ■ Using the portlet tag library 207 PART 2 DEVELOPING PORTLETS USING SPRING AND HIBERNATE.......................................................231 7 ■ Getting started with Spring Portlet MVC 233 8 ■ Annotation-driven development with Spring 281 9 ■ Integrating portlets with databases 334 v vi BRIEF CONTENTS PART 3 ADVANCED PORTLET DEVELOPMENT...........................373 10 ■ Personalizing portlets 375 11 ■ Communicating with other portlets 405 12 ■ Ajaxing portlets 437 13 ■ Reusable logic with portlet filters 494 14 ■ Portlet bridges 510 15 ■ Web Services for Remote Portlets (WSRP) 533 contents preface xix acknowledgments xxi about this book xxii about the cover illustration xxvii PART 1 GETTING STARTED WITH PORTLET DEVELOPMENT...................................................1 1 Introducing portals and portlets 3 1.1 What is a portal? 4 1.2 Benefits of web portals 6 Enriched user experience 6 ■ Unified information view 9 1.3 What is a portlet? 10 1.4 Why use portlets? 12 Inter-portlet communication vs. inter-servlet communication 12 ■ Portlets vs. widgets 13 Creating mashups 15 1.5 Portal infrastructure 15 The portlet container 15 ■ The portal server 16 vii viii CONTENTS 1.6 Getting started with Liferay Portal 18 Installing Liferay Portal 6.x 18 ■ Registering users with Liferay Portal 20 ■ Creating a public portal page in Liferay Portal 21 ■ Adding portlets to a Liferay Portal page 23 ■ Roles and permissions in Liferay Portal 24 1.7 Setting up the development environment 26 Configuring Eclipse IDE 26 ■ Setting up the project structure 34 1.8 The Hello World portlet example 35 Creating a Hello World portlet 35 ■ Building the Hello World project with Ant 39 ■ Building the Hello World project with Maven 42 ■ Adding the Hello World portlet to a portal page 43 ■ Undeploying a portlet application 46 1.9 Summary 46 2 The portlet lifecycle 48 2.1 Requirements for the User Registration portlet 49 2.2 Portlets vs. servlets—an in-depth look 51 Portlet and servlet containers 51 ■ Portlets—web components with multiple request-processing phases 52 2.3 Portlet URLs 54 Portlet URLs vs. servlet URLs 54 ■ Portlet URL types 56 2.4 Creating portlets 57 Creating portlets with the Portlet interface 57 ■ Creating portlets with the GenericPortlet class 60 2.5 Generating portlet content based on portlet mode 62 Writing content generation methods for each portlet mode 64 Defining support for portlet modes 67 2.6 Portlet development in depth 68 The Portlet API objects 69 ■ Creating JSPs to display portlet content 70 ■ The portlet deployment descriptor 72 Dispatching portlet requests using the PortletRequestDispatcher 73 Internationalization and localization using resource bundles 75 Portlet initialization parameters 76 ■ Creating portlet URLs 76 Container-runtime options 78
Description: