In a perfect world, people would post nice, kind, and decent content. They would reply to comments with constructive feedback and never lash out at one another. Unfortunately, sometimes people have a bad day and decide to take their frustration out on Joe Bloggs in the form of an inappropriate post. No worries though, Liferay Portal’s asset framework supports a system for flagging content in apps. Letting users flag inappropriate content takes much of the work off site administrators.
This tutorial shows you how to enable flagging of content in a portlet.
Follow these steps:
Make sure your entity is asset enabled.
Choose a read-only view of the entity for the flags. You can display them 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 portlet.
In the JSP, include the
<%@ taglib prefix="liferay-flags" uri="http://liferay.com/tld/flags" %>
-LocalServiceUtilclass to get the entity:
<% long entryId = ParamUtil.getLong(renderRequest, "entryId"); entry = EntryLocalServiceUtil.getEntry(entryId); %>
liferay-flags:flagstag to add the flags component:
<liferay-flags:flags className="<%= Entry.class.getName() %>" classPK="<%= entry.getEntryId() %>" contentTitle="<%= title %>" message="flag-this-content" reportedUserId="<%= reportedUserId %>" />
reportedUserIdattribute specifies the user who flagged the asset.
Great! Now you know how to let users flag content in your asset-enabled portlets.