Legacy Knowledge Base
公開されました Jun. 30, 2025

フラグメントのhtml/freemarkerコードでドロップダウンオプションのフィールドリファレンスを取得する方法は?

Written By

Sorin Pop

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.

問題

  • ステップ を再現しています:
    0. システム設定/Freemarker Engineで、制限された変数のリストからserviceLocatorを削除します。 (後でフラグメントコードで使えるように)
    1. Webコンテンツ構造を作成し、そこにSelect From Listフィールドを設置する。
    2. このフィールドにoption1、option2の2つのオプションを追加します。
    3. option2については、自動生成されたField Referenceをダブルクリックし、optref2
    4のように変更する。 詳細タブで「複数選択を許可」を有効にします(これは、自動生成されたフィールド参照に触れないオプションと、手動で変更したオプションの2種類の動作の違いを後で確認できるようにするためです)。 構造体を保存します。
    5. この構造の新しいウェブコンテンツを作成し、フィールドの両方のオプションにチェックを入れます。 発行する。
    6. サイトID(サイトのgroupid)とウェブコンテンツの記事のarticleId(journalarticleテーブル)を取得します:この後のhtml/freemarkerフラグメントコードで使用されます。
    7. デザイン/フラグメントに移動し、新しいフラグメントセットを作成した後、新しい基本フラグメントを作成し始めます。
    HTMLボックスに、次のようなコードを貼り付けます:

    <div class="fragment_1">
    	 [#assign srv = serviceLocator.findService("com.liferay.journal.service.JournalArticleLocalService")]
       [#assign article = srv.getArticle(20121,"44153")]
       [#assign document = saxReaderUtil.read(article.getContent())]
       [#assign rootElement = document.getRootElement()]
    	 
    	 [#list rootElement.elements() as dynamicElement ]
    	   [#if dynamicElement.attributeValue("name") == "Select23481751"]
    	      [#assign selection = dynamicElement.element("dynamic-content").getStringValue()]
    	      ${selection}
    	   [/#if]
    	 [/#list]
    </div>
    

    ここで
    20121 は groupid
    "44153" は articleid
    Select23481751 は step1 で作成したドロップダウンフィールドの自動生成フィールド参照(Advanced タブで確認できます)
    これらの値はテスト環境では異なる場合があります。

    結果: 右側の下のボックスに表示されます(スクリーンショットも添付します)。

    Option44203449 Option62081055

    (したがって、2番目のオプションでは、ステップ3で変更したフィールド参照ではなく、最初に自動生成されたフィールド参照が表示されます: optref2)

    期待される の結果:表示されるはずです。

    オプション44203449オプトレフ2

Environment

  • DXP 7.4

解決策

  • 記事からのDDMStructureは、DMFormFieldOptionsにアクセスするために使用されるべきである。

    以下は、適切なフラグメントhtmlコードの例である:

    <div class="fragment_1"> 
    [#assign srv = serviceLocator.findService("com.liferay.journal.service.JournalArticleLocalService")]
    [#assign article = srv.getArticle(20119,"44810")]
    [#assign document = saxReaderUtil.read(article.getContent())]
    [#assign rootElement = document.getRootElement()]
    [#assign ddmStructure = article.getDDMStructure()]

    [#list rootElement.elements() as dynamicElement ]
    [#if dynamicElement.attributeValue("field-reference") == "Select55199703"]
    [#assign ddmFormField = ddmStructure.getDDMFormField("Select55199703") /]
    [#assign ddmFormFieldOptions = ddmFormField.getDDMFormFieldOptions() /]
    [#assign optionsReferences = ddmFormFieldOptions.getOptionsReferences() /]

    [#assign selections = dynamicElement.element("dynamic-content").getStringValue()?word_list]
    [#list selections as optionValue]
    ${"option value:"} ${optionValue} <br>
    ${"option reference:"} ${optionsReferences[optionValue]}<br><br>
    [/#list]
    [/#if]
    [/#list]
    </div>

    この例では、レスポンスは次のようになります:
    option value: Option56521562
    option reference: Option56521562

    option value: Option70933281
    option reference: optref2

Did this article resolve your issue ?

Legacy Knowledge Base