RE: freeMarkerPortletPreferences has evaluated to null or missing

Jamie Sammons, modified 2 Years ago. New Member Posts: 10 Join Date: 2/28/23 Recent Posts

Hi,i have migrated a custom theme from Liferay 7.1 to Liferay 7.4. The theme deploys without any errors.
In the theme, in portal_normal.ftl i have  a runtime portlet (JournalContentPortlet  to display an article)

<#attempt>

    <!--Al parecer no existe freeMarkerPortletPreferences en 7.4-->

    <#assign VOID = freeMarkerPortletPreferences.setValue("portletSetupPortletDecoratorId", "barebone") />

    <#assign VOID = freeMarkerPortletPreferences.setValue("showListed", "false") />

    <#assign VOID = freeMarkerPortletPreferences.setValue("targetPortletId", "") />

    <script>

    console.log(${freeMarkerPortletPreferences})

    </script>

    <div class="col-11">

        <@liferay_portlet["runtime"]

            defaultPreferences="${freeMarkerPortletPreferences}"

            portletProviderAction=portletProviderAction.VIEW

            portletName="gsearchminiportlet"

        />

    </div>

    <#assign VOID = freeMarkerPortletPreferences.reset() />

    <div class="col-1 close-search-button-wrapper">

        <@liferay_aui["icon"] id="close-search-button" image="times" data={"show-id": "body"} markupView="lexicon" cssClass="neo-hover pull-right" />

    </div>

<#recover>

    <!-- Failed to load gsearch_search.ftl -->

</#attempt>

        ${freeMarkerPortletPreferences.reset()}

Im using freeMarkerPortletPreferences to set the runtime portlet preferences.
Unfortunatelly i get an exception at the line  <#assign VOID = freeMarkerPortletPreferences.setValue("portletSetupPortletDecoratorId", "borderless") />
The following has evaluted to null or missing:
==> freeMarkerPortletPreferences.setValue [in template "mytheme_SERVLET_CONTEXT_/templates/gsearch_search" at line 3, column 25]


Does anybody have any idea what might be the problem?
 

thumbnail
Olaf Kock, modified 2 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts

From a quick check, it looks like that API has changed dramatically. Your best and easiest bet might be to use the new standard "Master Page" to embed portlets on each page, instead of editing theme-side template code.

What have I done in my quick check?

grep -r "freeMarkerPortletPreferences" $SRC

which reveals a hit in FreeMarkerTemplateContextHelper.java
This line refers to TemplatePortletPreferences, which doesn't have any setValue method.

Following that path (specifically in FreeMarkerTemplateContextHelper), you might find a replacement option (e.g. as used in site-initializers), but my actual recommendation is to change your implementation and utilize Master Pages.

thumbnail
David H Nebinger, modified 2 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts

Yes, in 7.4 the syntax for embedding a portlet has changed... Try looking in the 7.4 themes for examples of the new syntax...