How do I show the tagging values as a dropdown list in Dialog?
Actually, I am trying to get and show all tagging values as a dropdown list in the dialog so that the author can choose the value from the dropdown list. I wrote the code but I am able to get only one tagging value by giving the array number. I have given my code below. Kindly help me to achieve the dropdown list.
package com.project.core.models.impl;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.Optional;
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
import org.apache.sling.models.annotations.injectorspecific.Self;
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.day.cq.tagging.Tag;
import com.day.cq.tagging.TagManager;
import com.project.core.models.PlanCards;
@Model(adaptables = {Resource.class, SlingHttpServletRequest.class},
adapters = { PlanCards.class},
resourceType = {PlanCardsImpl.RESOURCE_TYPE})
public class PlanCardsImpl implements PlanCards {
private static final Logger LOG = LoggerFactory.getLogger(PlanCardsImpl.class);
/**
* The resource type.
*/
protected static final String RESOURCE_TYPE = "project/components/nwt/slider";
@SlingObject
@7392697
private Resource currentRes;
@1961677
@7392697
private SlingHttpServletRequest request;
@SlingObject
private ResourceResolver resourceResolver;
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
private String dataUses;
@9944223
public String getDataUses() {
return dataUses;
}
public void setDataUses(String dataUses) {
this.dataUses = dataUses;
}
@PostConstruct
protected void init() {
String plancardTag = "/content/cq:tags/project/plan-cards/data-uses";
LOG.info("int() --> Plan cards default value");
final TagManager tagManager = currentRes.getResourceResolver().adaptTo(TagManager.class);
final List<String> filterTagList = new ArrayList<>();
LOG.info("Product Details Filter tag path:: {}", plancardTag);
if (StringUtils.isNotBlank(plancardTag)) {
final Tag tag = tagManager.resolve(plancardTag);
if (null != tag) {
tag.listChildren().forEachRemaining(childtag -> {
filterTagList.add(childtag.getTitle());
LOG.info("childtag.getName():: {}", childtag.getName());
});
}
}
LOG.info("filterTagList:: {}", filterTagList.toString());
if (StringUtils.isBlank(dataUses)) {
this.dataUses = filterTagList.get(1);
}
}
}