コミュニティアチーブメントバーを展開する。

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

この会話は、活動がないためロックされています。新しい投稿を作成してください。

解決済み

How to set datasource to ValueMapResourceWrapper.

Avatar

Level 2

I want use ValueMapResourceWrapper to create a Select field. How to set options by DataSource.

public class TestModel extends WCMUsePojo {
    @Override
    public void activate() throws Exception {
      ValueMapResourceWrapper wrapper = new ValueMapResourceWrapper(getResource(), "granite/ui/components/coral/foundation/form/select");
      wrapperProperties = wrapper.adaptTo(ValueMap.class);
      wrapperProperties.put("name", "fieldName");
      wrapperProperties.put("fieldLabel", "Label");

      List<Resource> itemValues = new ArrayList<>();
      for (a loop) {
        ValueMap vm = new ValueMapDecorator(new HashMap<String, Object>());
        vm.put("text", "text1");
        vm.put("value", "value1");
      }
      DataSource ds = new SimpleDataSource(itemValues.iterator());
      // How to set datasource
      

      getSlingScriptHelper().include(wrapper);
    }
}
1 受け入れられたソリューション

Avatar

正解者
Community Advisor

can you try with below, I am not sure if this is gonna work or not

request.setAttribute(DataSource.class.getName(), ds);

Arun Patidar

AEM LinksLinkedIn

元の投稿で解決策を見る

7 返信

Avatar

Community Advisor

Avatar

Level 2

Dear,

Thanks for your idea.

If the select field has resource and [datasource] node, it can work. But the select is created by [ValueMapResourceWrapper]. It is no resource, actual node and [datasource] node. I have try to below source code, but not work too.

 

wrapperProperties.put("datasource", ds);

Avatar

Level 10

@LiYanfei 

Could you please elaborate the need/use case for programmatic creation of select resource 

Avatar

Level 2

It use for page properties, and reference from CF Model.

eg: add a select field to CF Model,that be added on the page properties.

Avatar

Level 10

Dropdown field is available in CF model via the field named "Enumeration".

Did you try that already ?

Avatar

正解者
Community Advisor

can you try with below, I am not sure if this is gonna work or not

request.setAttribute(DataSource.class.getName(), ds);

Arun Patidar

AEM LinksLinkedIn

Avatar

Level 2

It not work.