Hands- On LiferayDXPLearn Portlet Developmentand Customization UsingOSGi ModulesApoorva PrakashShaik Inthiyaz BashaHands- On Liferay DXP: Learn Portlet Development and CustomizationUsing OSGi Modules Apoorva Prakash Shaik Inthiyaz Basha BANGALORE, India Nellore, AP, India ISBN-13 (pbk): 978-1-4842-8562-6 ISBN-13 (electronic): 978-1-4842-8563-3 https://doi.org/10.1007/978-1-4842-8563-3 Copyright 2022 by Apoorva Prakash and Shaik Inthiyaz Basha This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made.
The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Divya Modi Development Editor: James Markham Coordinating Editor: Divya Modi Cover designed by eStudioCalamar Cover image designed by Pixabay Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 New York Plaza, Suite 4600, New York, NY 10004-1562, USA. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail booktranslations@springernature.com; for reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub. For more detailed information, please visit https://www.apress. com/us/services/source-code.
Printed on acid-free paper To my father,Dr. Om Prakash Srivastava,to whom I owe everything,andwho inspired me but is not here to read this.Yes, life is like that sometimes!Apoorva PrakashTable of Contents About the Authors ix Acknowledgments xi Introduction xiii Chapter 1: OSGi Basics 1 Understanding OSGi 1 How Is OSGi Different? 2 A Deeper Look at OSGi 3 OSGi Architecture 3 OSGi Bundles 5 OSGi Bundle Rules 7 Importing and Exporting Bundles 8 OSGi Bundle Lifecycle 9 Bundle States 10 OSGi Components 12 OSGi Services 14 Service Registry 16 Declarative Services 16 Liferays OSGi Architecture 19 OSGi Features 20 Summary22 v Table of ConTenTs Chapter 2: Liferay Development Basics 23 The Liferay Workspace 23 Liferay Workspace Primer 24 Build Tools 26 Gradle 26 Maven 27 Introduction to Liferay Modules 29 The Blade CLI 32 Running Liferay the First Time 33 Running Liferay Application 34 Database Connectivity with Liferay DXP 37 Gogo Shell 42 Summary44 Chapter 3: Portlet Module Development 45 Introduction to Portlets 45 Portlet Specifications 47 Portlet Lifecycle 47 Portlet Modes and Window States 50 Portlet Mode 51 Window States 51 Java Standard Portlets 52 A Closer Look at HelloApressPortlet 56 Liferay Portlet Module (MVC Portlet) 58 Creating a Sample Liferay MVC Portlet 59 Understanding the Liferay MVC Portlet Controller 64 Understanding the Different URLs in the Liferay MVC Portlet 67 vi Table of ConTenTs Understanding Different Commands in the Liferay MVC Portlet 82 Implementing Window State96 Introduction to Other Portlet Modules 98 The Spring MVC Portlet98 Liferay Soy Portlet 99 JSF Portlet 99 Bean Portlet 99 Gogo Shell in Action 100 Gogo Shell from the Liferay Control Panel 103 Gogo Shell from the Blade CLI 104 Summary105 Chapter 4: Advanced Liferay Concepts 107 Inter-Portlet Communication 107 IPC via Public Render Parameters 108 IPC via Private Session Attributes 117 IPC via Server-Side Events 123 Client-Side IPC via Ajax 131 Client-Side IPC via Cookies 132 Liferay Message Bus 133 Synchronous Message Bus 140 Asynchronous Message Bus 142 Liferay Scheduler 145 Summary149 Chapter 5: Service Builder Concepts 151 Introduction to the Service Builder 151 Generating Services 153 Deep Diving Into the Code Generated by the Service Builder 164 vii Table of ConTenTs Customization via Implementation Classes 165 Remote Service Implementation 171 CRUD Operations 173 Finders 176 Dynamic Query 179 Custom SQL 181 Working with Remote Services 185 Headless REST APIs 185 Plain Web/REST Services 191 Summary194 Chapter 6: Liferay Customization 195 Overriding Language Keys 195 Global Language Property 196 Module Language Property 198 Customizing JSPs 200 Customization JSPs with Liferay APIs 201 Using OSGi Fragments or a Custom JSP Bag 207 Customizing Services Using Wrappers 212 Customizing OSGi Services 218 Customizing MVC Commands 220 Customizing Models Using Model Listeners 226 Expando Attributes 229 Pre and Post-Actions 236 Customizing Search 240 Summary245 Index 247 viii About the AuthorsApoorva Prakash is a Liferay-certified professional who has worked on Liferay for over a decade. Currently, he works with Schneider Electric Pvt Ltd., India, as a Liferay Expert and Engineering Lead for a team working on various projects of different technologies, including NodeJS, Python, AWS-based serverless technologies, and so on. Apoorva has defined the architecture of multiple portals, including large employee portals, ecommerce sites, and so on, in Liferay for over 12 years and counting. His other work areas include NodeJS, Python, AWS, and Kubernetes. Development and deployment are his passions, and he is inherently very keen on attention to detail.
He is an avid blogger, and his blog has been mentioned in the Liferay community round-up several times. Apoorva has completed his masters degree in computer application from the school of computer science, Apeejay Institute of Technology, Greater Noida, Uttar Pradesh. His other hobbies are tech blogging and wildlife photography. ix abouT The auThors Shaik InthiyazBasha is a Liferay Architect and Technical Expert at Schneider Electric Pvt Ltd., India. He is an expert in Content Management Systems (CMS) and Amazon Web Service (AWS). Inthiyaz currently holds the position of Platform Architect in a group involved in developing Liferay and Elastic Search applications.
Next page