내 커뮤니티 업적 표시줄을 확대합니다.

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.