Legacy Knowledge Base
公開されました Jul. 2, 2025

Web コンテンツのレンダリング時に #null を指定して FreeMarker テンプレートを実行するとエラーが発生します

Written By

Sergio Alonso

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

問題

  • Web コンテンツをレンダリングしようとすると、Liferay DXP ログに次のエラーが表示されます。
    2021-02-12 11:41:48.911 ERROR [http-nio-8080-exec-9][runtime:59] Error executing FreeMarker template
    FreeMarker template error:
    The following has evaluated to null or missing:
    ==> webContentData.title [in template "20101#20128#null" at line 14, column 11]

    ----
    Tip: It's the step after the last dot that caused this error, not those before it.
    ----
    Tip: If the failing expression is known to legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
    ----

    ----
    FTL stack trace ("~" means nesting-related):
    - Failed at: ${webContentData.title} [in template "20101#20128#null" at line 14, column 9]
    ----

    Java stack trace (for programmers):
    ----
    freemarker.core.InvalidReferenceException: [... Exception message was already printed; see it above ...]
    at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:134)
    at freemarker.core.EvalUtil.coerceModelToTextualCommon(EvalUtil.java:479)
    at freemarker.core.EvalUtil.coerceModelToStringOrMarkup(EvalUtil.java:401)
    at freemarker.core.EvalUtil.coerceModelToStringOrMarkup(EvalUtil.java:370)
    at freemarker.core.DollarVariable.calculateInterpolatedStringOrMarkup(DollarVariable.java:100)
    at freemarker.core.DollarVariable.accept(DollarVariable.java:63)
    at freemarker.core.Environment.visit(Environment.java:331)
    at freemarker.core.Environment.visit(Environment.java:337)
    at freemarker.core.Environment.process(Environment.java:310)
    at freemarker.template.Template.process(Template.java:383)
    at com.liferay.portal.template.freemarker.internal.FreeMarkerTemplate.processTemplate(FreeMarkerTemplate.java:154)
    at com.liferay.portal.template.BaseTemplate.processTemplate(BaseTemplate.java:163)
    at com.liferay.journal.internal.transformer.JournalTransformer.doTransform(JournalTransformer.java:367)
    at com.liferay.journal.internal.transformer.JournalTransformer.transform(JournalTransformer.java:103)
    at com.liferay.journal.internal.util.JournalUtil.transform(JournalUtil.java:424)
    at com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.getArticleDisplay(JournalArticleLocalServiceImpl.java:7962)
    at com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.getArticleDisplay(JournalArticleLocalServiceImpl.java:2516)
    ...
    ...
    ...
  • Web コンテンツには構造がありますが、関連するテンプレートはありません。

Environment

  • Liferay DXP 7.2
  • Liferay DXP 7.3

解決策

  • この問題は、構造が「Web コンテンツ」タイプのフィールド (内部的には「ddm-journal-article」と示される) を定義し、このフィールドに構造に基づく Web コンテンツで値が割り当てられていない場合に発生します。
  • この場合、Liferay は、デフォルトの FreeMarker テンプレート journal-article.ftlを使用して「ddm-journal-article」フィールドを処理します。 このテンプレートは、「ddm-journal-article」フィールドが Web コンテンツのタイトルなどの特定の値を提供することを前提としています。
  • ただし、フィールドには値がないため、テンプレートは null 値を取得し、これにより FreeMarker テンプレートからの解析エラーが発生します。
  • この問題を解決するには、次の 2 つのオプションがあります。
    • 「Web コンテンツ」フィールドに値を入力する必要があります。
    • または、Web コンテンツに関連付けられたテンプレートが必要です。

Did this article resolve your issue ?

Legacy Knowledge Base