Expand my Community achievements bar.

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

Mark Solution

This conversation has been locked due to inactivity. Please create a new post.

SOLVED

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 Accepted Solution

Avatar

Correct answer by
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

View solution in original post

7 Replies

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

Correct answer by
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.