I've a multifield where-in I can add multiple tags. Now what I'm trying is to fetch the title of the tag. Attached are the screenshots of the dialog.
Resource Type of the field is : /libs/cq/gui/components/coral/common/form/tagfield
This is the method with which I had tried - Problem is it throws null pointer exception.
private void getCourses(List<String> coursesType, List<String> coursesTypeList) {
TagManager tagManager;
Iterator<String> coursesubjectList = coursesType.iterator();
while (coursesubjectList.hasNext()) {
resourceResolver = request.getResourceResolver();
tagManager = resourceResolver.adaptTo(TagManager.class);
Tag tag = tagManager.resolve(coursesubjectList.next());
if(tag != null){
coursesTypeList.add(tag.getTitle());
}
}
}
Please suggest any corrections or you can even help me with the reqd code snippet.
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Hi @arindam6600 ,
Can you please check if your resourceResolver object is null?
Also refer this code: https://gist.github.com/ksurendra/900b2c5ce943fd85112e4de376aaaf20
Regards,
Santosh
Views
Replies
Total Likes
Hi @arindam6600 ,
Can you please check if your resourceResolver object is null?
Also refer this code: https://gist.github.com/ksurendra/900b2c5ce943fd85112e4de376aaaf20
Regards,
Santosh
Views
Replies
Total Likes
Hi @arindam6600
I would suggest you to use tagpicker instead of using tagfield. It allows you to select multiple tags so you don't need to use multifield with tagfield.
sling:resourceType:cq/gui/components/common/tagspicker
Below code snippet should work
@Inject private String[] tags; private void getCourses(String[] tags, List<String> coursesTypeList) { resourceResolver = request.getResourceResolver(); TagManager tagManager = resourceResolver.adaptTo(TagManager.class); for (String tag: tags) { Tag tag = tagManager.resolve(tag); if(tag != null){ coursesTypeList.add(tag.getTitle()); } } }
Views
Replies
Total Likes