Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

TagManager resolve not working

Avatar

Avatar
Boost 10
Level 2
AD-Engineer
Level 2

Likes

10 likes

Total Posts

28 posts

Correct Reply

0 solutions
Top badges earned
Boost 10
Validate 1
Ignite 1
Give Back 3
Give Back
View profile

Avatar
Boost 10
Level 2
AD-Engineer
Level 2

Likes

10 likes

Total Posts

28 posts

Correct Reply

0 solutions
Top badges earned
Boost 10
Validate 1
Ignite 1
Give Back 3
Give Back
View profile
AD-Engineer
Level 2

31-05-2021

Hi,

 

I am trying to create a filter component - to filter based on tags. The idea is to pass tags from a specific path to front, so user can choose from dropdown.

I am having an issue, with Tag Manager methods, like resolve.

Code below:

 @Override
    public String getAllTags(){
        Tag tag = null;
        TagManager tagManager = null;
    
        tagManager =  resourceResolver.adaptTo(TagManager.class);
        tag = tagManager.resolveByTitle("Region");
      

        String name = tagManager.getNamespaces()[3].getTitle();
        return tag.getPath();
    }

 

This is just a test method. I know that the return type should be List<Tag>, but for now I just want to get a specific tag path, to understand hot this works. But it is returning null. I know most of the times this issue is related to user permissions, but I already updated the permission to read for content/cq:tags. Thanks!

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Give Back 100
Level 10
asutosh_jena
Level 10

Likes

570 likes

Total Posts

687 posts

Correct Reply

197 solutions
Top badges earned
Give Back 100
Boost 500
Affirm 100
Ignite 1
Establish
View profile

Avatar
Give Back 100
Level 10
asutosh_jena
Level 10

Likes

570 likes

Total Posts

687 posts

Correct Reply

197 solutions
Top badges earned
Give Back 100
Boost 500
Affirm 100
Ignite 1
Establish
View profile
asutosh_jena
Level 10

31-05-2021

Hi @AD-Engineer 

 

Please follow the below approach:

 

Create a VO/POJO class with all the desired fields. I added only 2 for DEMO.

public class TagVO {
private String tagName;
private String tagTitle;

public String getTagName() {
return tagName;
}

public void setTagName(String tagName) {
this.tagName = tagName;
}

public String getTagTitle() {
return tagTitle;
}

public void setTagTitle(String tagTitle) {
this.tagTitle = tagTitle;
}
}

 

 Create a Model class and call it in component:

@Model(adaptables = Resource.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class TestModel {

private static final Logger log = LoggerFactory.getLogger(TestModel.class);

@SlingObject
private ResourceResolver resourceResolver;

private List<TagVO> tagList;

@PostConstruct
protected void init() {
log.info("***** :: Start :: *****");
tagList = new ArrayList<>();
String tagPath = "/content/cq:tags/brands/whatever"; // Here you will pass the parent path to all tags. Ensure anonumous user access is there for this path.
TagManager tagManager = resourceResolver.adaptTo(TagManager.class);
if (tagManager != null) {
Tag tagFromPath = tagManager.resolve(tagPath);
Iterator<Tag> tagIterator = tagFromPath.listChildren();
tagIterator.forEachRemaining(tag -> {
TagVO tagVO = new TagVO();
tagVO.setTagName(tag.getName());
tagVO.setTagTitle(tag.getTitle());
tagList.add(tagVO);
});
}
log.info("***** :: End :: *****");
}

public List<TagVO> getTagList() {
return tagList;
}
}

 

HTL:

<sly data-sly-use.menuobj="com.aem.core.models.TestModel">
<sly data-sly-list.listObj="${menuobj.tagList}">
<li value="${listObj.tagName}">${listObj.tagTitle}</li>
</sly>
</sly>

HTL script can be modified to show as dropdown. I just added as simple list item.

 

Hope this helps!

Thanks 

Answers (0)