Developing Portlet Applications
Think of your Liferay portal as a pizza crust (sit down, you can go order a real pizza when we’re done here). In Chapter 2 we equipped you with Liferay’s tools for developing your pizza, and Liferay comes with some basic toppings that make for a pretty good pizza out of the box (i.e., our core portlets and built-in functionality). Of course, your boss might demand anchovies, and Liferay definitely doesn’t come with anchovies. So what do you do? You take our tools, get some anchovies (your app’s source code), and integrate them with the pizza (Liferay). In this chapter we’re going to show you how to develop portlet projects to top your Liferay pizza in such a way that the end-user won’t be able to tell the difference between your custom portlet and our core portlets.
In the last chapter we showed you how to create Liferay plugin projects, and if you followed along with our exercises, you now have a project to hold Liferay portlets. Unfortunately we don’t really have any portlets in there yet. So we’re going to get to business on actually creating an application with the Liferay development tools we’ve already introduced to you. It’s fitting to start with portlet development, because portlets are the most basic, most commonly used type of Liferay plugin you’ll develop. We’ll create and deploy a simple portlet using the Plugins SDK. It will allow a customized greeting to be saved in the portlet’s preferences and then display it whenever the portlet is viewed. Then we’ll clean up the portlet’s URLs by adding a friendly URL mapping. Lastly we’ll localize the portlet.
You’re free to use any framework you prefer to develop your portlets, including Struts, Spring MVC, JSF, and Vaadin. Here we’ll use the Liferay MVCPortlet framework, because it’s simple, lightweight, and easy to understand.
You don’t have to be a Java developer to take advantage of Liferay’s built-in features (such as user and organization management, page building, and content management). An application developed using Ruby or PHP can be deployed as a portlet using the Plugins SDK, and it will run seamlessly inside of Liferay. For examples, check out the liferay-plugins repository from GitHub at http://github.com/liferay.
We’ll discuss the following topics as we learn about developing portlets for Liferay:
- Creating a Portlet Project
- Anatomy of a Portlet Project
- Writing the My Greeting Portlet
- Understanding the Two Phases of Portlet Execution
- Passing Information from the Action Phase to the Render Phase
- Developing a Portlet with Multiple Actions
- Adding Friendly URL Mapping to the Portlet
- Localizing Your Portlet
- Implementing Configurable Portlet Preferences
- Creating Plugins to Share Templates, Structures, and More
First, let’s create the portlet that we’ll use throughout this chapter.