Expand my Community achievements bar.

SOLVED

Dynamic dropdown with checkboxes

Avatar

Level 6

 

Hi Team,

 

I have a requirement to populate dynamic dropdown with checkboxes. I can able to populate dynamic values but along with that checkboxes also has to be populated.

 

I tired below code:

  public void doGet(SlingHttpServletRequest req, SlingHttpServletResponse res) {
        List<Resource> resourceList = new ArrayList<>();
        resolver = req.getResourceResolver();
        req.setAttribute(DataSource.class.getName(), EmptyDataSource.instance());
        lobResource = resolver.getResource(acsPathLOB);
        String key = StringUtils.EMPTY;
        String value = StringUtils.EMPTY;
        for (Resource resource : lobResource.getChildren()) {
            key = resource.getValueMap().get("jcr:title", String.class);
            value = resource.getValueMap().get("value", String.class);
            valueMap = new ValueMapDecorator(new HashMap<>());
            valueMap.put("text", key);
            valueMap.put("value", value);
            try {
                resourceList.add(new ValueMapResource(resolver, new ResourceMetadata(),
                        "/libs/granite/ui/components/coral/foundation/form/checkbox", valueMap));
            } catch (Exception ex) {
                log.error("--exception--:{}", ex.getMessage());
            }
        }
        DataSource ds = new SimpleDataSource(resourceList.iterator());
        req.setAttribute(DataSource.class.getName(), ds);
    }
 
but only values are getting populated any suggestions to populate as checkboxes.
 
Thanks in advance,
Keerthi K.
1 Accepted Solution

Avatar

Correct answer by
Community Advisor
1 Reply

Avatar

Correct answer by
Community Advisor