Issue

You want to dynamically populate form fields in a dialog box in CQ. For example, you want to define a select box by configuring a Select component in dialog.any as follows:

...
/Type "AtomLine"
            /Sub
              {
              /mySelectAtom
                {
                /Type "Select"
                /Option
                  {
                  /option0
                    {
                    /value "red"
                    /text "Scarlet"
                    }
                  /option1
                    {
                    /value "green"
                    /text "Lime"
                    }
                  /option2
                    {
                    /value "blue"
                    /text "Azure"
                    }
                  }
                }
              }
... 

Solution

For the example above, you hard code all for the select options in dialog.any. However, you can define and manage these options as an external resource and to populate the dialog dynamically.

Use an OwnerDraw type in dialog.any instead of Select to specify a script that draws a CFC component programmatically. In the script, you can retrieve the values from an external resource and populate the dialog. So, to change the Select example to use an OwnerDraw do the following.

  1. Change dialog.any to call a custom script to draw the form field via OwnerDraw type ... /Type "AtomLine" /Sub { /mySelectAtom { /Type "OwnerDraw" /file "/apps/[yourApp]/components/dynamicDialogComponent/dynamicSelect.esp" } } ... 
  2. Define a Java class to access an external resource and return java.util.Map with all the options. public class DialogValues { public static Map getSelectOptions(String atomName) { Map optionsMap = new LinkedHashMap(); // get select options and put them in a map // ... return optionsMap; } }
  3. Define /apps/[yourApp]/components/dynamicDialogComponent/dynamicSelect.esp that calls the Java class and renders the CFC select object with options returned in java.util.Map. Place the code bellow in dynamicSelect.esp.

The example uses CFC.Controls.Select. But you can use the same OwnerDraw approach with other CFC objects. In fact, you can use the OwnerDraw to draw any section of the dialog which cannot be defined using .any notation.

The CFC scripting objects are documented on http://docs.day.com, in cfclib.pdf distributed with Communiqué 4.x and via in the Help system of your instance.

이 작업에는 Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License의 라이센스가 부여되었습니다.  Twitter™ 및 Facebook 게시물은 Creative Commons 약관을 적용받지 않습니다.

법적 고지 사항   |   온라인 개인 정보 보호 정책