This wiki does not contain official documentation and is currently deprecated and read only. Please try reading the documentation on the Liferay Developer Network, the new site dedicated to Liferay documentation. DISCOVER Build your web site, collaborate with your colleagues, manage your content, and more. DEVELOP Build applications that run inside Liferay, extend the features provided out of the box with Liferay's APIs. DISTRIBUTE Let the world know about your app by publishing it in Liferay's marketplace. PARTICIPATE Become a part of Liferay's community, meet other Liferay users, and get involved in the open source project. Enable Portlet Rating Feature
Table of Contents [-]
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!