about this book

Portlets are web components, like servlets, that are responsible for accessing dis-tinct applications, systems, or data sources and generating markup fragments to pre-sent the content to web portal users. The Java Portlet technology simplifies the proc-ess of developing web portals by providing personalization and content aggregation as an integral part of the technology.

Portlets in Action is a step-by-step guide to developing portlets using the Java Portlet technology. The text is complemented by numerous examples to demonstrate how different features of the Java Portlet technol-ogy are used in developing portlets. The book covers not only the core Port-let 2.0 API, but also goes beyond to cover leading frameworks that simplify portlet development.

Roadmap

The book is divided into three parts.

Part 1 introduces the Java Portlet technology and includes chapters 1–6. If you’re new to portlets, you should read chapters in se-quence.

Chapter 1 introduces you to the world of portlets and web portals. In this chapter, you’ll learn what portlets and web portals are, and why they’re so important in today’s world. This chapter lays the foundation for learning the portlet concepts described in later chapters. We’ll also look at how to install a Liferay Portal server, set up the Eclipse IDE and a portlet application’s project structure, and develop a Hello World portlet.

Chapter 2 takes you an inch deep into the portlet world and presents a simple User Registration portlet. This chapter introduces the portlet lifecycle and some of the commonly used Portlet 2.0 classes and interfaces. It also in-troduces container-runtime options, which provide additional portlet con-tainer features to the portlets. This chapter sets the stage for diving deep into the Java Portlet technology.

Chapters 3 and 4 describe the Portlet 2.0 API in the context of a Book Catalog portlet. In these chapters, we’ll look at the different request and response objects used in portlets and the specific features they provide. We’ll see how JavaScript and CSS are programmatically added to portal pages, how portlet content is localized using resource bundles, how portlets are secured, and how portlet content is cached. We’ll also look at the details of the different container-runtime options defined by the portlet specification.

Chapter 5 shows you how to develop an example Book Portal web por-tal using Life-ray Portal. This chapter shows how a portal server’s built-in portlets can help minimize the effort involved in building a web por-tal. This chapter also shows how the Life-ray Plugins SDK can be used to develop a custom theme and layout for a web portal. Readers who are using the GateIn Portal with the examples in this book can refer to appendix A, which describes how to develop a web portal using GateIn Portal.

Chapter 6 introduces portlet tag library tags, which are used for develop-ing portlets with JSP as the view technology. Different portlet tag library tags are introduced in the context of a Book Catalog portlet.

Part 2 of this book shows you how to develop portlets using Spring Port-let MVC, Spring JDBC, and Hibernate. This part includes chapters 7–9, and it’s recommended that you read chapters 7 and 8 se-quentially.

Chapter 7 introduces the Spring Framework and the classes and inter-faces of Spring Portlet MVC. This chapter describes the Spring Portlet MVC architecture and lays the foundation for learning more advanced concepts in Spring Portlet MVC, and it uses a variety of examples to explain different Spring Portlet MVC concepts.

Chapter 8 takes a deep dive into the annotation-driven development support in Spring Portlet MVC and in Spring in general. This chapter covers Spring’s form tag library, JSR 303 (Bean Validation), the Spring Validation API, dependency injection using JSR 330 and JSR 250, and Spring’s TestContext framework for unit and integration testing. All the concepts are introduced in the context of the example Book Catalog port-let.

Chapter 9 looks at how you can write database-driven portlets using the Spring JDBC module and Hibernate. This chapter also provides a quick in-troduction to aspect-oriented programming and transaction support in Spring. The concepts described in this chapter are put to use while developing the example Book Catalog portlet.

Part 3 of the book covers advanced concepts in portlet development, including inter-portlet communication, WSRP, personalization, portlet bridges, Ajax/Comet, and portlet filters. This part of the book includes chapters 10–15, and there’s no need to read the chapters in this part sequentially.

Chapter 10 looks at the personalization support available in portlets and how it can be used to personalize the content and behavior of a portlet. In the context of the Book Catalog portlet, this chapter shows how preferences are defined for a portlet, saved into a persistent store, and later retrieved to per-sonalize the content and behavior of the portlet.

Chapter 11 looks at different techniques for inter-portlet communica-tion, using sessions, public render parameters, and events. The examples in this chapter show how each communication technique is implemented.

Chapter 12 introduces Ajax and how it’s used for developing highly responsive portlets. The chapter looks at different Ajax frameworks, like jQuery, DWR, and Dojo, to show how each one of them can be used to incorporate Ajax features in portlets. This chapter also looks at how Comet (or Reverse Ajax) is used for developing real-time portlets. The chapter makes use of numerous code examples to demonstrate these concepts.

Chapter 13 introduces you to the world of portlet bridges, which are used to expose existing web applications as portlets. The chapter shows how a JSF 2.0 web application and a Wicket web application can be exposed as portlets using portlet bridges.

Chapter 14 looks at developing portlets that make use of portlet filters for pre- and post-processing portlet requests and responses.

Chapter 15 looks at how Web Services for Remote Portlets (WSRP) can be used by a web portal to publish portlets to the external world, so that they can then be consumed by other web portals.

Appendix A introduces the GateIn Portal and describes the steps re-quired to create an example Book Portal web portal.

Appendix B shows how to configure Liferay Portal to use a MySQL da-tabase.

How to use this book

This book contains numerous working examples that demonstrate how to de-velop portlets using Portlet 2.0 and other leading frameworks, like Spring Portlet MVC, Hibernate, DWR, Spring JDBC, Dojo, jQuery, and so on. The book contains CODE REFERENCE callouts to inform you when you should import an Eclipse pro-ject into your Eclipse IDE for reference. I recommend that you install the Liferay Portal or GateIn Portal and try out the examples while reading the book, and that you refer to the source code when it’s suggested in the text. This approach will help you learn portal and portlet development more effectively.

Who should read this book?

In writing this book, I haven’t assumed that you have any prior knowledge of the Java Portlet technology or the different frameworks referenced here. The con-cepts are described in such a way that readers who have prior knowledge of web ap-plication development using JSPs and servlets can easily understand the content.

The different frameworks covered in this book, like Spring Portlet MVC, Spring JDBC, Hibernate, Spring AOP, DWR, Dojo, jQuery, and so on, are gently introduced, so that the example portlets can be easily under-stood even if you’re new to these frameworks.

If you have prior experience working with web portals using Portlet 1.0, you’ll also find this book useful, because it explains the new features introduced in Portlet 2.0 and how to go about creating portlets that make use of frameworks like Spring Portlet MVC, Spring AOP, Spring JDBC, Spring Transaction, Hibernate, Dojo, jQuery, and DWR.

Because the book provides complete coverage of Portlet 2.0’s features and integration with different frameworks, portal architects will also find this book useful for architecting solutions around Portlet 2.0.

Source code conventions

This book contains numerous examples that include portlet classes, XML con-figuration files for portlets and portal servers, JSP pages, build.xml files for the Ant build tool, and pom.xml files for the Maven build tool. The code explained in the book targets Liferay Portal server. GateIn Portal–specific Eclipse projects addi-tionally contain a README.TXT file that specifies GateIn Portal–specific changes made to the portlets developed for Liferay Portal.

In the text, a monospace typeface is used to denote code (JSP, Java, and XML) as well as Java methods, JSP tag names, and other code elements.

Java, HTML, and XML can all be quite verbose, and in many cases the original source code (available online) has been reformatted, adding line breaks and reworking indentation, to accommodate the available page space in the book. In rare cases, even this was not enough, and listings include line continuation markers ().

Additionally, comments in the source code have been removed from the listings presented in the book. Code annotations accompany many of the source code listings, highlighting important concepts. In some cases, num-bered bullets link to explanations in the text following the listing.

Software requirements

To deploy and run the example portlets in this book, you need to install GateIn Portal 3.1, Liferay Portal 6 CE GA3, or any Portlet 2.0–compliant portlet con-tainer. GateIn Portal 3.1 and Liferay Portal 6 CE GA3 are freely downloadable and have low memory footprints. The examples in this book make use of Liferay Portal and GateIn Portal, which come bundled with the Tomcat server.

Chapters 3 and 4 make use of Jetspeed and GlassFish Server with OpenPortal Portlet Container to show that support for some of the Portlet 2.0 features varies from one portal server to another. If you want to test the ex-ample Book Catalog portlet described in chapters 3 and 4, you’ll need to install Jetspeed 2.2.1 and GlassFish Server 3.0.1 with OpenPortal Portlet Container 2.1.

To run the example portlets in chapter 9, you’ll also need to in-stall the MySQL database and HeidiSQL client, the details of which are pro-vided in appendix B.

Source code downloads

The source code for all the examples in this book is available from Man-ning’s web site: www.manning.com/PortletsinAction/. The examples have been provided for both GateIn Portal and Liferay Portal servers, and they’ve been tested on GateIn Portal 3.1 and Life-ray Portal 6 CE GA3, but they’ll work on any Portlet 2.0–compliant portlet container with little or no modification.

The source code explained in this book is for Liferay Portal. Because GateIn Portal required some minor changes to the source code, these changes have been recorded in the README.TXT file that you’ll find in the Eclipse projects for GateIn Portal.

To run the examples, you can download the Tomcat bundle for GateIn Portal or Liferay Portal and deploy the example portlets as described in chap-ter 1 (for Liferay Portal) and in appendix A (for GateIn Portal).

The source code for the book is divided into separate Eclipse projects, and the names of the folders reflect the chapter to which the example be-longs. For instance, if the folder name is ch7_Controllers, the source code is for chapter 7. Each example can be built by using either Ant or Maven, and the steps required are explained in chapter 1.

Author Online

Purchase of Portlets in Action includes free access to a private web forum run by Manning Publications where you can make comments about the book, ask technical questions, and receive help from the author and from other users. To ac-cess the forum and subscribe to it, point your web browser to www.manning.com/PortletsinAction. This page provides information on how to get on the forum once you’re regis-tered, what kind of help is available, and the rules of conduct on the forum.

Manning’s commitment to our readers is to provide a venue where a meaningful dialog between individual readers and between readers and the author can take place. It is not a commitment to any specific amount of participation on the part of the author, whose contribution to the Author Online forum remains voluntary (and unpaid). We suggest you try asking the author some challenging questions lest his interest stray!

The Author Online forum and the archives of previous discussions will be accessible from the publisher’s website as long as the book is in print.