In only a few lines of code, you can use a taglib to enable ratings for your app’s content. The steps here show you how. For more information on this taglib and ratings in general, see Ratings.
Follow these steps to enable ratings in your app. Note that these steps use a sample Guestbook app as an example. This app lets users leave simple messages in a guestbook.
Make sure your entity is asset enabled.
Choose a read-only view of the entity for which you want to enable ratings. You can display ratings in one of your portlet’s views, or if you’ve implemented asset rendering you can display them in the full content view in the Asset Publisher app.
In the JSP, include the
<%@ taglib prefix="liferay-ui" uri="http://liferay.com/tld/ui" %>
ParamUtilto get the entity’s ID from the render request. Then create an entity object using the
-LocalServiceUtilclass. Here’s an example that does this for a guestbook entry in the example Guestbook app:
<% long entryId = ParamUtil.getLong(renderRequest, "entryId"); entry = EntryLocalServiceUtil.getEntry(entryId); %>
liferay-ui:ratingstag to add the ratings component for the entity. This example uses the stars rating type:
<liferay-ui:ratings className="<%=Entry.class.getName()%>" classPK="<%=entry.getEntryId()%>" type="stars" />