Creating JSPs for Displaying Custom Assets in the Asset Publisher

Adding Asset Features to Your UI

Step 2 of 5

Before proceeding, you must tie up a loose end from the previous step. Remember that you implemented getJspPath methods in your GuestbookAssetRenderer and EntryAssetRenderer classes to JSPs that don’t exist yet. These methods return paths to JSPs the Asset Publisher uses to display the assets’ full content. The getJspPath method of GuestbookAssetRenderer returns "/asset/guestbook/full_content.jsp", and the getJspPath method of EntryAssetRenderer returns "/asset/entry/full_content.jsp". It’s time to create these JSPs.

Follow these steps:

  1. In the guestbook-web module project, create a new folder called asset under the resources/META-INF/resources folder. Add two folders to this new folder: entry and guestbook.

  2. Create a new file called full_content.jsp in the /asset/guestbook folder. This JSP displays a guestbook asset’s full content. Add the following code to this file:

    <%@include file="../../init.jsp"%>
    
    <%
    Guestbook guestbook = (Guestbook)request.getAttribute("gb_guestbook");
    
    guestbook = guestbook.toEscapedModel();
    %>
    
    <dl>
            <dt>Name</dt>
            <dd><%= guestbook.getName() %></dd>
    </dl>
    

    This JSP grabs the guestbook object from the request and displays the guestbook’s name. In GuestbookAssetRenderer, the getJspPath method added the gb_guestbook request attribute:

    request.setAttribute("gb_guestbook", _guestbook);
    

    The guestbook’s toEscapedModel method belongs to the GuestbookModelImpl class, which was generated by Service Builder. This method returns a safe guestbook object (a guestbook in which each field is HTML-escaped). Calling guestbook = guestbook.toEscapedModel() before displaying the guestbook name ensures that your JSP won’t display malicious code that’s masquerading as a guestbook name.

  3. Next, in the /asset/entry folder, create a full_content.jsp for displaying a guestbook entry asset’s full content. Add the following code to this file:

    <%@include file="../../init.jsp"%>
    
    <%
    Entry entry = (Entry)request.getAttribute("gb_entry");
    
    entry = entry.toEscapedModel();
    %>
    
    <dl>
            <dt>Guestbook</dt>
            <dd><%= GuestbookLocalServiceUtil.getGuestbook(entry.getGuestbookId()).getName() %></dd>
            <dt>Name</dt>
            <dd><%= entry.getName() %></dd>
            <dt>Message</dt>
            <dd><%= entry.getMessage() %></dd>
    </dl>
    

This JSP shows a combination of fields from the Guestbook and the selected Entry.

After deploying your changes, test your new JSPs by clicking a guestbook’s or guestbook entry’s title in the Asset Publisher. The Asset Publisher renders full_content.jsp:

Figure 1: When you click the title for a guestbook or guestbook entry in the Asset Publisher, your full_content.jsp should be displayed.

Figure 1: When you click the title for a guestbook or guestbook entry in the Asset Publisher, your `full_content.jsp` should be displayed.

By default, when displaying an asset’s full view, the Asset Publisher displays additional links for social media so you can publicize your asset. The Back icon and the View in Context link return you to the Asset Publisher’s default view.

« Adding Asset Features to Your User InterfaceEnabling Tags, Categories, and Related Assets for Guestbooks »
Was this article helpful?
0 out of 0 found this helpful