Dynamic dropdown with checkboxes | Community
Skip to main content
Keerthi0555
New Participant
August 7, 2023
Solved

Dynamic dropdown with checkboxes

  • August 7, 2023
  • 1 reply
  • 649 views

 

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.
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

Sady_Rifat
Sady_RifatAccepted solution
New Participant
August 7, 2023