« Volver a Portlets

Enable Portlet Rating Feature

(Redirigido desde 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 archivos adjuntos
77993 Accesos
Promedio (24 Votos)
La valoración media es de 3.0416666666666665 estrellas de 5.
Comentarios
Respuestas anidadas Autor Fecha
There are some forums may be useful in this... kuhajeyan gunaratnam 18 de noviembre de 2008 22:54
How do I do the same for each page. The above... Karthik Krishnamoorthy 26 de marzo de 2009 16:44
5 tsrtas Ramiro Gomez 1 de mayo de 2012 10:20
one more Ramiro Gomez 1 de mayo de 2012 10:20
There seem to be some issue while counting... Ajit Rai 18 de noviembre de 2013 5:45
How to clear my ratings on click on a button... Chandarsekhar Rajoli 13 de diciembre de 2013 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
Publicado el día 18/11/08 22:54.
How do I do the same for each page. The above covers the scenario for portlets but for each page?
Publicado el día 26/03/09 16:44 en respuesta a kuhajeyan gunaratnam.
Publicado el día 1/05/12 10:20.
Publicado el día 1/05/12 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 ?
Publicado el día 18/11/13 5:45.
How to clear my ratings on click on a button Reset ?
Publicado el día 13/12/13 1:16.