« 返回到 Portlets

Enable Portlet Rating Feature

(从 Adding Rating to a portlet 进行重定向)

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 附件
77997 查看
平均 (24 票)
满分为 5,平均得分为 3.0416666666666665。
评论
讨论主题回复 作者 日期
There are some forums may be useful in this... kuhajeyan gunaratnam 2008年11月18日 下午10:54
How do I do the same for each page. The above... Karthik Krishnamoorthy 2009年3月26日 下午4:44
5 tsrtas Ramiro Gomez 2012年5月1日 上午10:20
one more Ramiro Gomez 2012年5月1日 上午10:20
There seem to be some issue while counting... Ajit Rai 2013年11月18日 上午5:45
How to clear my ratings on click on a button... Chandarsekhar Rajoli 2013年12月13日 上午1:16

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
在 08-11-18 下午10:54 发帖。
How do I do the same for each page. The above covers the scenario for portlets but for each page?
在 09-3-26 下午4:44 发帖以回复 kuhajeyan gunaratnam
在 12-5-1 上午10:20 发帖。
在 12-5-1 上午10:20 发帖。
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 ?
在 13-11-18 上午5:45 发帖。
How to clear my ratings on click on a button Reset ?
在 13-12-13 上午1:16 发帖。