Hi,
I have created the tags under
/content/cq:tags/excel-challenge
When I try to get the list of all the tags under the above path, I get ArrayIndexOutOfBoundsException
Resource tagpath=resolver.getResource("/content/cq:tags/excel-challenge");
Tag[] tags=tagManager.getTags(tagpath);
logger.info("Length of tags:"+tags.length);
Thanks in advance.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi,
In order to get the list of all tags under the given tag path, we need to resolve the respective path as "Tag" using "TagManager", followed by listChildren() or listAllSubTags() for immediate/direct child tags or tags of utmost depth respectively.
Tag tag = tagManager.resolve("/content/cq:tags/we-retail");
Iterator<Tag> tagItr = tag.listChildren();
Below line that you have used in your code will return all the tags set on the given resource (not the child tags from the given tag path)
Eg. Tags set on page or asset resource.
Tag[] tags=tagManager.getTags(tagpath);
Views
Replies
Total Likes
Hi,
I think you might be using the wrong method.
If you want to get a list of all the tags you created under /content/cq:tags/excel-challenge, you should be using the second one
Views
Replies
Total Likes
Hi,
In order to get the list of all tags under the given tag path, we need to resolve the respective path as "Tag" using "TagManager", followed by listChildren() or listAllSubTags() for immediate/direct child tags or tags of utmost depth respectively.
Tag tag = tagManager.resolve("/content/cq:tags/we-retail");
Iterator<Tag> tagItr = tag.listChildren();
Below line that you have used in your code will return all the tags set on the given resource (not the child tags from the given tag path)
Eg. Tags set on page or asset resource.
Tag[] tags=tagManager.getTags(tagpath);
Views
Replies
Total Likes
Thanks @Vijayalakshmi_S for the help!
I'm able to get the list of tags now
I have a few nodes under content/orders which contains jcr property cq:tags.
Is there any way I could get the list of nodes tagged with specific tags, e.g., Pen? I tried using find method, but it's giving null iterator
String[] tagnames={"Pen","Desk"};
RangeIterator<Resource> it = tagManager.find("/content/orders",tagnames);
Thanks!
Views
Replies
Total Likes
Hi,
Good to know that it worked.
For getting resources tagged with specific tags, in the tagnames array, use the values as is available in the jcr:content node of respective content path.
Eg. Pen is tagged in the path say, /content/orders/xyx.
Navigate to /content/orders/xyx/jcr:content and look for cq:tags property and use the same value as it is available there. (That is the actual tag Id of the respective tag)
Views
Replies
Total Likes
I tried using specific path for a specific order2 as below
Resource tagpath3=resolver.getResource("/content/orders/order2");
Tag[] tags=tagManager.getTags(tagpath3);
it's returning the tag node, However, I want to get list of all the order nodes containing specific tag, "Pencil".
Is there any way I could do that using find method?
Thanks!
Views
Replies
Total Likes
The snippet in your previous comment will help get the same. Just that you need to use the exact tagId value in tagnames array. Looks like you have used the tag title - Pen/ Pencil..
TagId value should be different with namespace.
String[] tagnames={"Pen","Desk"}; // Use the exact Tag Id values in this array.
RangeIterator<Resource> it = tagManager.find("/content/orders",tagnames)
Example:
In the image below, tag Id is we-retail:activity/biking
Views
Replies
Total Likes
I have used the exact tag names.
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Likes
Replies