Adding Comments to your App

Users adding comments to your content makes your site come alive. Instead of you statically giving users information, now the flow goes both ways. Liferay DXP’s asset framework makes it easy to add a comment system to your app.

Figure 1: Your JSP lets users comment on content in your portlet.

Figure 1: Your JSP lets users comment on content in your portlet.

This tutorial shows you how to add the comment feature for your application’s content.

Follow these steps:

  1. Make sure your entity is asset enabled.

  2. Choose a read-only view of the entity for the comments. You can display the comments component in your portlet’s view, or if you’ve implemented asset rendering, you can display it in the full content view in the Asset Publisher portlet.

  3. Include the Liferay-UI taglib and Portlet taglib declarations in your JSP:

    <%@ taglib prefix="liferay-ui" uri="" %>      
    <%@ taglib prefix="portlet" uri="" %>
  4. Use ParamUtil to get the entity’s ID from the render request. Then create an entity object using the -LocalServiceUtil class. Below is an example configuration:

    long entryId = ParamUtil.getLong(renderRequest, "entryId");
    entry = EntryLocalServiceUtil.getEntry(entryId);
  5. Create a collapsible panel for the comments using the liferay-ui:panel-container and liferay-ui:panel tags. This makes the discussion area hide-able. Below is an example configuration:

    <liferay-ui:panel-container extended="<%=false%>"
      id="guestbookCollaborationPanelContainer" persistState="<%=true%>">
      <liferay-ui:panel collapsible="<%=true%>" extended="<%=true%>"
        id="guestbookCollaborationPanel" persistState="<%=true%>"
  6. Next, create a URL for the discussion using the portlet:actionURL tag:

    <portlet:actionURL name="invokeTaglibDiscussion" var="discussionURL" />
  7. Finally, add the discussion with the liferay-ui:discussion tag. Pass the current URL using the redirect attribute, so the user can return to the JSP after making a comment. You can use PortalUtil.getCurrentURL((renderRequest)) to get the current URL from the request object. Below is an example configuration:

        <liferay-ui:discussion className="<%=Entry.class.getName()%>"
          formAction="<%=discussionURL%>" formName="fm2"
          ratingsEnabled="<%=true%>" redirect="<%=currentURL%>"
          userId="<%=entry.getUserId()%>" />

If you haven’t already connected your portlet’s view to the JSP for your entity, you can refer here to see how to connect a portlet’s main view JSP to an entity’s view JSP.

Great! Now you know how to let users comment on content in your asset enabled portlets.

Adding, Updating, and Deleting Assets for Custom Entities

Adding Permissions to Resources

Rendering an Asset

Applying Social Bookmarks

« Applying Social BookmarksRating Assets »
¿Fue útil este artículo?
Usuarios a los que les pareció útil: 0 de 0