この記事では、Liferayプラットフォーム(PortalとDXPの両方)で、 serviceLocator プロパティを定義する場所が変更されたことを説明します。
Portal 6.2のこの機能に慣れている開発者は、このプロパティを有効または無効にすることで、FreemarkerまたはVelocityの特定の呼び出しでWeb Content Templatesを作成できるようにすることができます。 そのため、DXP 7.0で何が変わったのか気になるところでしょう。
解決策
Portal 6.2 では、プロパティは portal.properties ファイルに設定されていました。
# Set a comma delimited list of variables the FreeMarker engine cannot
# have access to. This will affect Dynamic Data List templates, Journal
# templates, and Portlet Display templates.
#
freemarker.engine.restricted.variables=\
objectUtil,\
serviceLocator,\
staticFieldGetter,\
staticUtil,\
utilLocator
# Set a comma delimited list of variables the Velocity engine cannot
# have access to. This will affect Dynamic Data List templates, Journal
# templates, and Portlet Display templates.
#
velocity.engine.restricted.variables=\
serviceLocator,\
staticFieldGetter,\
utilLocator
デフォルトでは、 serviceLocator への呼び出しは制限されています。 その使用を許可するために、開発者は portal-ext.properties ファイルを更新する必要がありました。 DXP 7.0では、これらの設定はコントロールパネルに移されました。
FreeMarkerの場合、 コントロールパネル → 設定 → システム設定 → Foundation → FreeMarker Engine → Restricted Variablesに移動します。
Velocityの場合、 コントロールパネル → 設定 → システム設定 → Foundation → Velocity Engine → Restricted Variablesに移動します。
テンプレートが serviceLocatorを使用できるようにするには、フィールドの値を削除し、 Updateをクリックします。 次に、アプリケーションサーバーを再起動し、変更を適用します。 この変更により、 serviceLocator 呼び出しを使用できるWebコンテンツ・テンプレートを作成できるようになりました。