use of com.adobe.granite.ui.components.ds.SimpleDataSource in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class OptionsImpl method populateOptionItemsFromDatasource.
@SuppressWarnings("unchecked")
private void populateOptionItemsFromDatasource() {
if (StringUtils.isBlank(datasourceRT)) {
return;
}
// build the options by running the datasource code (the list is set as a request attribute)
RequestDispatcherOptions opts = new RequestDispatcherOptions();
opts.setForceResourceType(datasourceRT);
RequestDispatcher dispatcher = request.getRequestDispatcher(resource, opts);
try {
if (dispatcher != null) {
dispatcher.include(request, response);
} else {
LOGGER.error("Failed to include the datasource at " + datasourceRT);
}
} catch (Exception e) {
LOGGER.error("Failed to include the datasource at " + datasourceRT, e);
}
// retrieve the datasource from the request and adapt it to form options
SimpleDataSource dataSource = (SimpleDataSource) request.getAttribute(DataSource.class.getName());
if (dataSource != null) {
Iterator<Resource> itemIterator = dataSource.iterator();
if (itemIterator != null) {
while (itemIterator.hasNext()) {
Resource item = itemIterator.next();
OptionItem optionItem = item.adaptTo(OptionItem.class);
if (optionItem != null && (optionItem.isDisabled() || StringUtils.isNotBlank(optionItem.getValue()))) {
optionItems.add(optionItem);
}
}
}
}
}
Aggregations