Building Personal Community in Liferay Portal 5.2

7 min read

Besides public web sites, it would be nice if we could provide a personal community, that is, My Community, for each registered user. In My Community, users can have a set of public and private pages. Here you can save your favorite games, videos and playlists, and the My Street theme — your background color.

As shown in the following screenshot, there is a page my_street with a portlet myStreet, where an end user can sign up, log in, or handle an issue such as Forgot Your Password?

Building Personal Community in Liferay Portal 5.2o

When you click on the SIGN UP button, this My Street portlet will allow the end users to set up his/her account such as creating a nickname, password hint question, password hint answer, your password, and verify password. Further, as the end user, you can set up favorite games, videos and playlists, and background color.

You can have your own favorites: number of favorites displayed in My Street (for example, 4, 20, and 35) and My Street theme, (for example, default, Abby Cadabby, Bert, Big Bird, Cookie Monster, and so on). A set of default My Street themes is predefined in /cms_services/images/my_street/ under the folder $CATALINA_HOME/webapps/ and you can choose any one of them at any time. At the same time, you can upload a photo to your own Book Street web page.

When logged in, the My Street theme will be applied on Home page, Games landing page, Videos landing page, and Playlist landing page. For example, current user’s My Street theme could be applied on Playlist landing page.

You may play videos, games, and playlists when you visit the web site When you find your favorite videos, games, and playlists, you can add them into My Street. As shown in the following screenshot, you could be playing a playlist Tickle Time. If you are interested in this playlist, just click on the Add to My Street button. The playlist Tickle Time will be added into My Street as your favorite playlist. In this section, we will show how to implement these features.

Building Personal Community in Liferay Portal 5.2

Customizing user model

First, let’s customize user model in service.xml in order to support extended user and user preferences. To do so, use the following steps:

  1. Create a package com.ext.portlet.user in the /ext/ext-impl/src folder.
  2. Create an XML file service.xml in the package com.ext.portlet.comment and open it.
  3. Add the following lines in this file and save it:
  4. <?xml version="1.0"?><!DOCTYPE service-builder PUBLIC "-//
    Liferay//DTD Service Builder 5.2.0//EN" "
    <service-builder package-path="com.ext.portlet.user">
    <entity name="ExtUser" uuid="false" local-service="true"
    persistence. ExtUserPersistenceImpl">
    <column name="userId" type="long" primary="true" />
    <column name="favorites" type="int" />
    <column name="theme" type="String" />
    <column name="printable" type="boolean" />
    <column name="plainPassword" type="String" />
    <column name="creator" type="String" />
    <column name="modifier" type="String" />
    <column name="created" type="Date" />
    <column name="modified" type="Date" />
    <entity name="ExtUserPreference" uuid="false"
    local-service="true" remote-service="true"
    <column name="userPreferenceId" type="long" primary="true" />
    <column name="userId" type="long"/>
    <column name="favorite" type="String" />
    <column name="favoriteType" type="String" />
    <column name="date_" type="Date" />

The code above shows the customized user model, including userId associated with USER_ table, favourites, theme, printable, plainPassword, and so on. This code also shows user preferences model, including userPreferenceId, userId, favorite (for example, game/video/playlist UID), favoriteType (for example, game/video/playlist), and the updated date date_. Of course, these models are extensible. You can extend these models for your unique current needs or future requirements.

Enter the following tables into database through command prompt:

create table ExtUser (
userId bigint not null primary key,
creator varchar(125), modifier varchar(125),
created datetime null,modified datetime null,
favorites smallint, theme varchar(125),
plainPassword varchar(125), printable boolean );
create table ExtUserPreference (
usePreferenceId bigint not null primary key,
userId bigint not null,favorite varchar(125),
favoriteType varchar(125),date_ datetime null

The preceding code shows the database SQL script for customized user model and user preference model. Similar to XML model ExtUser, this code shows the userId, favorites, theme, plainPassword, and printable table fields. Again, for the XML model ExtUserPreference, this code shows the userId, favorite, favoriteType, date_, and userPreferenceId table fields.

Afterwards, we need to build a service with ServiceBuilder. After preparing service.xml, you can build services. To do so, locate the XML file /ext/ext-impl/buildparent.xml, open it, add the following lines between </target> and <target name=”build-service-portlet-reports”>, and save it:

<target name="build-service-portlet-extUser">
<antcall target="build-service">
<param name="service.file"
value="src/com/ext/portlet/user/service.xml" />

When you are ready, just double-click on the Ant target build-service-portletextUser. ServiceBuilder will build related models and services for extUser and extUserPreference.


Building the portlet My Street

Similar to how we had built portlet Ext Comment, we can build the portlet My Street as follows:

  1. Configure the portlet My Street in both portlet-ext.xml and liferay-portlet-ext.xml files.
  2. Set title mapping in the file.
  3. Add the My Street portlet to the Book category in the liferay-display.xml file.
  4. Finally, specify Struts actions and forward paths in the struts-config.xml and tiles-defs.xml files, respectively.

Then, we need to create Struts actions as follows:

  1. Create a package com.ext.portlet.my_street.action in the folder /ext/ext-impl/src.
  2. Add the Java files,, and in this package.
  3. Create a Java file in this package and open it.
  4. Add the following methods in and save it:
  5. public static ExtUser getUser(long userId){
    ExtUser user = null;
    user = ExtUserLocalServiceUtil.getExtUser(userId);
    catch (Exception e){}
    if(user == null){
    user = ExtUserLocalServiceUtil.createExtUser(userId);
    catch (Exception e) {}
    return user;
    public static void deleteUser(long userId) {
    catch (Exception e){}
    public static void updateUser(ActionRequest actionRequest,
    long userId) {
    /* ignore details */
    public static List<ExtUserPreference> getUserPreferences(
    long userId, int limit){
    /* ignore details */
    public static ExtUserPreference addUserPreference(
    long userId, String favorite, String favoriteType){
    /* ignore details */

As shown in the code above, it shows methods to get ExtUser and ExtUserPreference, to delete ExtUser, and to add and update ExtUser and ExtUserPreference.

In addition, we need to provide default values for private page and friendly URL in as follows:


The code above shows the default private page of my_street as false, default friendly URL of my_street as /my_street. Therefore, you can use VM service to generate a URL in order to add videos, games, and playlists into My Street.

Adding Struts view page

Now we need to build Struts views pages view.jsp, forget_password.jsp, create_account.jsp, congratulation.jsp, and congrates_uid.jsp. The following are main steps to do so:

  1. Create a folder my_street in /ext/ext-web/docroot/html/portlet/ext/.
  2. Create JSP file pages view.jsp, view_password.jsp, userQuestions.jsp, edit_account.jsp, create_account.jsp, congratulation.jsp, and congrates_uid.jsp in /ext/ext-web/docroot/html/portlet/ext/my_street/.

Note that congrates_uid.jsp is used for the pop-up congratulation of Add to My Street. When you click on the Add to My Street button, a window with congrates_uid.jsp will pop up. userQuestions.jsp is used when the user has forgotten the password of My Street, view_password.jsp is for general view of My Street, congratulation.jsp is used to represent successful information after creating user account, and edit_account.jsp is used to create/update user account.


Please enter your comment!
Please enter your name here