« 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:
\


liferay-ui:ratings

<liferay-ui:ratings
className="<%= yourportlet.class.getName() %>"
classPK="<%= yourportlet.getResourcePrimKey() %>"
url='<%= themeDisplay.getPathMain() + "/relativepathtoaction" %>'
/>
 }}}

\\ 
**sample:**
{{{
<liferay-ui:ratings
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.

Sample:

<%
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

 yourliferayinstallation\webapps\ROOT\WEB-INF\  


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">


<struts-config>
	<action-mappings>

		<!-- 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>
**<action path="/wiki/rate_wiki" type="com.liferay.portlet.ratings.action.RateEntryAction" /> **
	</action-mappings>
</struts-config>
 


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
18211 Views
Average (10 Votes)
Comments

Showing 4 Comments

kuhajeyan gunaratnam
11/18/08 10:54 PM

There are some forums may be useful in this follow up,
https://www.liferay.com/web/guest/community/forums?p_p_id=19&p_p_lifecycle=0&­p_p_state=normal&p_p_mode=view&p_p_col_id=column-2&p_p_col_count=1&_19_struts_ac­tion=%2Fmessage_boards%2Fview_message&_19_messageId=796927&_19_threadView=tree

ht­tp://www.liferay.com/web/guest/community/forums/-/message_boards/message/246827;­jsessionid=9AABDD31BFBB4C959326649CC8494B3B

http://www.liferay.com/web/guest/comm­unity/forums/-/message_boards/message/500485

Karthik Krishnamoorthy
3/26/09 4:44 PM

How do I do the same for each page. The above covers the scenario for portlets but for each page?

Ramiro Gomez
5/1/12 10:20 AM

5 tsrtas

Ramiro Gomez
5/1/12 10:20 AM

one more