Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-123118

Unable to use 'portletRequestModel' in Web Content Template mapped to Fragment on a Content Page or Display Page Template

Details

    Description

      In some cases is is necessary to use a Web Content Template to render advanced information about a Web Content Article on a Display Page Template (via mapping the Template to a Fragment).

      In some cases it is also necessary for the Web Content Structure to contain links to another Web Content Article.

      In order to retrieve Field information about the embedded/child Web Content Article it is necessary to use:

       

      JournalArticleService.getArticleContent

       

      to retrieve the field data through execution of a second Web Content Template.

      In 7.3, the number of variants of getArticleContent has reduced, and each of the available 3 methods now requires portletRequestModel is passed in as a parameter.

      In order to generate this object the user must instantiate a portletRequestModel object.  This approach works successfully within, for example, an Asset Publisher list of content with embedded content articles, but fails when used via mapping a Fragment.

      Example code for the calling Template:

      <#assign webContentData = jsonFactoryUtil.createJSONObject(Owner.getData()) /><span class="label label-lg label-success">
       <span class="label-item label-item-expand"> 
       Contributor: ${webContentData.title} 
       </span>
       </span>
       <#assign resourcePrimKey = webContentData.classPK?number />
       <#assign className = webContentData.className />
       <#if className == "com.liferay.journal.model.JournalArticle">
       <#assign JournalArticleLocalService = serviceLocator.findService("com.liferay.journal.service.JournalArticleLocalService") /> 
       <#assign journalArticle = JournalArticleLocalService.fetchLatestArticle(resourcePrimKey) />
           <#assign portletRequestModel = objectUtil("com.liferay.portal.kernel.portlet.PortletRequestModel", renderRequest, renderResponse) />
       <#assign content = JournalArticleLocalService.getArticleContent(journalArticle, "185797", "view", themeDisplay.getLocale().toString(), portletRequestModel, themeDisplay) />
       ${content}
       </#if>

      In this example "Owner" is a Web Content Field within the Web Content Structure.  It contains two Text fields which are rendered by template "185797".

      This approach worked in 7.2 where the portletRequestModel was not a required parameter for getArticleContent (there were deprecated methods that did not require portletRequestModel) but these have been removed in 7.3

      When the template is executed it generates the following error:

      Nov 04 15:46:08.587 build-22 liferay[liferay-5765dc4f6d-dvnl6] Java constructor "com.liferay.portal.kernel.portlet.PortletRequestModel.com.liferay.portal.kernel.portlet.PortletRequestModel(javax.portlet.PortletRequest, javax.portlet.PortletResponse)" threw an exception; see cause exception in the Java stack trace.

      The full details of the error generated are included in the attached log "portletRequestModel Error Log.txt"

      Steps to reproduce:

      The error can be generated quite simply, although this is not a real-world scenario:

      1. Remove objectUtil from Restricted Values field in Freemarker Engine of System Settings
      2. Create a Web Content Template ("Simple Test Template") for Basic Web Content with a single line
        <#assign portletRequestModel = objectUtil("com.liferay.portal.kernel.portlet.PortletRequestModel", renderRequest, renderResponse) />
      3. Create a Display Page Template mapped to Basic Web Content, deploy the Paragraph fragment and map the fragment to Simple Test Template
      4. Mark the Display Page Template the Default for Basic Web Content
      5. Create a Web Content Article using Basic Web Content, and then use Search to find the article
      6. Click on the article in search results to display the Web Content Article in the Display Page Template
      7. Observe the error on screen and in the logs

      Steps to reproduce for a real-world scenario:

      In order to replicate more fully, in addition to the above, the following is needed:

      1. A Web Content Structure (e.g. "Embedded Web Content") which includes a Web Content field
      2. A Web Content Template (e.g. "Child Content") for the embedded Web Content field
      3. A Web Content Template (e.g. "Link to Child Content") for the parent Web Content Structure that uses getArticleContent to render "Child Content", and therefore requires code similar to the example provided earlier.

      Note: The same error can also be observed with regular Content Pages.

      Attachments

        Issue Links

          Activity

            People

              yang.cao Yang Cao
              benjamin.turner Benjamin Turner
              Kiyoshi Lee Kiyoshi Lee
              Ruben Pulido Ruben Pulido
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                1 year, 37 weeks, 1 day ago

                Packages

                  Version Package
                  7.3.X
                  7.4.3.9 CE GA9
                  Master