Dynamic Dropdown using datasource
Hi,
I have a dynamic dropdown that is populated using a datasource. In my servlet, I use a ResourceResolver obtained from a service user instead of the request object(this is done to avoid granting permissions to individual group users.). Although I can successfully retrieve the values on the backend with the service user, they are not displaying in the component dialog on the frontend.
All necessary permissions are granted to the service user, and the datasource object contains values. However, it is not appearing on the frontend.I suspect the issue arises when executing request.setAttribute(DataSource.class.getName(), ds);
It functions correctly when the ResourceResolver is obtained from the current request object.
Below is the code snippet. Any help is appreciated.
try (ResourceResolver resolver = ResourceResolverUtils.getDefaultServiceResourceResolver(resourceResolverFactory)) {
request.getSession().setAttribute(DataSource.class.getName(), EmptyDataSource.instance());
List<String> subGroupList = userGroupRetriever.getUsersAndGroups(resolver, parentGroupName, true);
List<Resource> fakeResourceList = new ArrayList<>();
for (String subGroup : subGroupList) {
ValueMap vm = new ValueMapDecorator(new HashMap<>());
vm.put("value", subGroup.trim().toLowerCase());
vm.put("text", subGroup.trim());
fakeResourceList.add(new ValueMapResource(resolver, new ResourceMetadata(), JcrConstants.NT_UNSTRUCTURED, vm));
}
DataSource ds = new SimpleDataSource(fakeResourceList.iterator());
request.getSession().setAttribute(DataSource.class.getName(), ds);
// request.setAttribute(DataSource.class.getName(), ds);
} catch (Exception e) {
log.error("Exception occurred {}", ExceptionUtils.getStackTrace(e));
}