In this chapter 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. Last we’ll clean up the portlet’s URLs by adding a friendly URL mapping.

You’re free to use any framework you prefer to develop your portlets, including Struts, Spring MVC, or JSF. 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.

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

First, let’s create the portlet that we’ll use throughout this chapter.

Creating a Portlet

Portlet creation using the Plugins SDK is simple. There’s a portlets folder inside the Plugins SDK folder, where your portlet projects reside. The first thing to do is give your portlet a project...

Read More

Anatomy of a Portlet

A portlet project is made up of at least three components: Java Source. Configuration files. Client-side files (.jsp, .css, .js, graphics files, etc.). When using Liferay’s Plugins SDK, these files...

Read More

Writing the My Greeting Portlet

Let’s make our portlet do something useful. First, we’ll give it two pages: view.jsp: displays the greeting and provides a link to the edit page. edit.jsp: shows a form with a text field, allowing...

Read More

Understanding the Two phases of Portlet Execution

Our portlet needs two execution phases, the action phase and the render phase. Multiple execution phases can be confusing to developers used to regular servlet development or used to other...

Read More

Passing Information from the Action Phase to the Render Phase

There are two ways to pass information from the action phase to the render phase. The first way is through render parameters. In the processAction method you can invoke the setRenderParameter...

Read More

Developing a Portlet with Multiple Actions

Right now our portlet only has two views: the default view and edit view. Adding more views is easy, and you can link to them using the mvcPath parameter in your renderURL. But we only have one...

Read More

Adding Friendly URL Mapping to the Portlet

When you click the Edit greeting link, you’re taken to a page with a URL that looks like this: http://localhost:8080/web/guest/home?p_p_id=mygreeting_WAR_mygreetingportlet...

Read More

Localizing your Portlet

If your portlets target an international audience, you can localize the user interface. Localizing your portlet’s language is done using language keys for each language you wish to support. You can...

Read More

Implementing Configurable Portlet Preferences

Portlet Preferences are properties for storing basic portlet configuration data. Preferences are often used by administrators to provide customized views of a portlet to subsets of users or even...

Read More

Creating Plugins to extend Plugins

For Liferay plugins, you can create a new plugin that extends an existing one. By extending a plugin, you can use all its features in your new plugin while keeping your changes/extensions separate...

Read More


You’ve covered a lot of ground learning Liferay Portlet development. You created a portlet project, studied its anatomy, and created the “My Greeting Portlet”. You understood the Action phase and...

Read More
0 (0 Votes)
Summary Previous