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);
}
}
Solved! Go to Solution.
Views
Replies
Total Likes
can you try with below, I am not sure if this is gonna work or not
request.setAttribute(DataSource.class.getName(), ds);
Hi,
Please check this https://github.com/arunpatidar02/aemaacs-aemlab/blob/master/core/src/main/java/com/community/aemlab/...
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);
Could you please elaborate the need/use case for programmatic creation of select resource
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.
Dropdown field is available in CF model via the field named "Enumeration".
Did you try that already ?
can you try with below, I am not sure if this is gonna work or not
request.setAttribute(DataSource.class.getName(), ds);
It not work.
Views
Likes
Replies
Views
Likes
Replies
Views
Like
Replies