Enabling Tags, Categories, and Related Assets for Guestbook Entries

Adding Asset Features to Your UI
Step 4 of 5

Enabling tags, categories, and related assets for guestbook entries is similar to enabling them for guestbooks. It’s so similar, you can refer back to the previous step for a detailed explanation.

Open your guestbook-web module’s guestbookwebportlet/edit_entry.jsp file. Replace its content with the following code:

<%@ include file="../init.jsp" %>

long entryId = ParamUtil.getLong(renderRequest, "entryId");

Entry entry = null;

if (entryId > 0) {
    entry = EntryLocalServiceUtil.getEntry(entryId);

long guestbookId = ParamUtil.getLong(renderRequest, "guestbookId");

<portlet:renderURL var="viewURL">

    backURL="<%= viewURL.toString() %>"
    title="<%= entry == null ? "Add Entry" : entry.getName() %>"

<portlet:actionURL name="addEntry" var="addEntryURL" />

<aui:form action="<%= addEntryURL %>" name="fm">
    <aui:model-context bean="<%= entry %>" model="<%= Entry.class %>" />

            <aui:input name="name" />

            <aui:input name="email" />

            <aui:input name="message" />

            <aui:input name="entryId" type="hidden" />

            <aui:input name="guestbookId" type="hidden" 
            "<%= entry == null ? guestbookId : entry.getGuestbookId() %>" />

<liferay-ui:asset-categories-error />
                    <liferay-ui:asset-tags-error />
                    <liferay-ui:panel defaultState="closed" 
                    extended="<%= false %>" id="entryCategorizationPanel" 
                    persistState="<%= true %>" title="categorization">
                                    <aui:input name="categories" 
                                    type="assetCategories" />

                                    <aui:input name="tags" type="assetTags" />

                    <liferay-ui:panel defaultState="closed" 
                    extended="<%= false %>" id="entryAssetLinksPanel" 
                    persistState="<%= true %>" title="related-assets">
                                            "<%= Entry.class.getName() %>"
                                            classPK="<%= entryId %>"

        <aui:button type="submit" />

        <aui:button onClick="<%= viewURL.toString() %>" type="cancel" />

Test your JSP by using the Guestbook portlet to add and update Guestbook entries. Try adding and removing tags, categories, and related assets. All these operations should work.

Well done! Next, you’ll enable comments and ratings for guestbook entries.