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 each other. Unfortunately, sometimes people have a bad day and decide to take their frustrations out in inappropriate posts. No worries though, the 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 content flagging in a portlet.
Figure 1: Flags for letting users mark objectionable content are enabled in the Message Boards portlet.
Follow these steps to enable content flagging in your app:
-
Make sure your entity is asset enabled.
-
Choose a read-only view of the entity you want to enable flags on. You can display flags in one of your app’s views, or if you’ve implemented asset rendering you can display it in the full content view in the Asset Publisher app.
-
In your JSP, include the
liferay-flags
taglib declaration:<%@ taglib prefix="liferay-flags" uri="http://liferay.com/tld/flags" %>
-
Use
ParamUtil
to get the entity’s ID from the render request. Then use your-LocalServiceUtil
class to create an entity object:<% long entryId = ParamUtil.getLong(renderRequest, "entryId"); entry = EntryLocalServiceUtil.getEntry(entryId); %>
-
Use the tag
liferay-flags:flags
to add the flags component:<liferay-flags:flags className="<%= Entry.class.getName() %>" classPK="<%= entry.getEntryId() %>" contentTitle="<%= title %>" message="flag-this-content" reportedUserId="<%= reportedUserId %>" />
The
reportedUserId
attribute specifies the user who flagged the asset.
Great! Now you know how to let users flag content in your asset-enabled apps.