How to set datasource to ValueMapResourceWrapper. | Community
Skip to main content
LiYanfei
Level 2
Mar 4, 2022 6:58 AM UTC
Solved

How to set datasource to ValueMapResourceWrapper.

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.
arunpatidar
arunpatidarAccepted solution
New Participant
Mar 15, 2022 4:14 PM UTC

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

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

Arun Patidar

7 replies

arunpatidar
New Participant
Mar 7, 2022 11:36 AM UTC
LiYanfei
LiYanfeiAuthor
Level 2
Mar 7, 2022 1:28 PM UTC

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);
Translate
Vijayalakshmi_S
Level 10
Mar 8, 2022 6:40 PM UTC

@liyanfei 

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

Translate