« Back to Portlets

Enable Portlet Rating Feature

Introduction #

Ranking a page or portlet can be used to measure popularity. Liferay provides a page rating portlet, this can be added to any application via "Add Application".

Adding a ranking to a portlet can be done with liferay:ui tags. Liferay provides a way of extending a portlet capabilities via ui tags.

Incorporate Ranking in a Portlet #

To do this, you need to incorporate a UI tag into the portlet, to enable ranking. You need the className and primaryKey of any object to associate it with comments and/or ranks and you need to add the struts action path as well. Basically liferay-ui:ratings looks like this:


className="<%= yourportlet.class.getName() %>"
classPK="<%= yourportlet.getResourcePrimKey() %>"
url='<%= themeDisplay.getPathMain() + "/relativepathtoaction" %>'

className="<%= WikiPage.class.getName() %>"
classPK="<%= wikiPage.getResourcePrimKey() %>"
url='<%= themeDisplay.getPathMain() + "/wiki/rate_wiki" %>'

Procedure #

Here is the simplified procedure.

  • Add className - your portlet className
  • Add classprimarykey

Finding your class primary key #

Your portlet class primary key can be found by using request object.


JournalArticleDisplay articleDisplay = (JournalArticleDisplay)request.getAttribute(WebKeys.JOURNAL_ARTICLE_DISPLAY);

  • Add struts action path

add struts action path to your stuts-config.xml, ideally instead adding your entry to struts-config.xml, it should be added to struts-config-ext.xml. it is in the location of


It should be included within the <action mapping> tags, after adding your struts action path your struts-config-ext.xml may look like following,

<?xml version="1.0"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">


		<!-- Reports -->

		<action path="/ext/reports/view_reports" type="com.ext.portlet.reports.action.ViewReportsAction">
			<forward name="portlet.ext.reports.view" path="portlet.ext.reports.view" />
			<forward name="portlet.ext.reports.view_reports" path="portlet.ext.reports.view_reports" />
**<action path="/wiki/rate_wiki" type="com.liferay.portlet.ratings.action.RateEntryAction" /> **

look for the bolded lines within the <action mapping> tag

Thats all, you should be able to use ratings in your any portlet from now!

0 Attachments
Average (21 Votes)
The average rating is 3.142857142857143 stars out of 5.
Threaded Replies Author Date
There are some forums may be useful in this... kuhajeyan gunaratnam November 18, 2008 10:54 PM
How do I do the same for each page. The above... Karthik Krishnamoorthy March 26, 2009 4:44 PM
5 tsrtas Ramiro Gomez May 1, 2012 10:20 AM
one more Ramiro Gomez May 1, 2012 10:20 AM
There seem to be some issue while counting... Ajit Rai November 18, 2013 5:45 AM
How to clear my ratings on click on a button... Chandarsekhar Rajoli December 13, 2013 1:16 AM

There are some forums may be useful in this follow up,


Posted on 11/18/08 10:54 PM.
How do I do the same for each page. The above covers the scenario for portlets but for each page?
Posted on 3/26/09 4:44 PM in reply to kuhajeyan gunaratnam.
Posted on 5/1/12 10:20 AM.
Posted on 5/1/12 10:20 AM.
There seem to be some issue while counting average ratings. It doesn't show the round figure upto one decimal point rather it displays the average for more than 10 decimal points ? is it a known bug ? any fix available for the same ?
Posted on 11/18/13 5:45 AM.
How to clear my ratings on click on a button Reset ?
Posted on 12/13/13 1:16 AM.