How to set datasource to ValueMapResourceWrapper. | Community
Skip to main content
LiYanfei
New Participant
March 4, 2022
Solved

How to set datasource to ValueMapResourceWrapper.

  • March 4, 2022
  • 1 reply
  • 1751 views

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

public class TestModel extends WCMUsePojo { @9944223 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); } }
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

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

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

1 reply

arunpatidar
New Participant
March 7, 2022
LiYanfei
LiYanfeiAuthor
New Participant
March 7, 2022

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);
Vijayalakshmi_S
New Participant
March 8, 2022

@liyanfei 

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