Hello All,
I am trying to read the cq:tags - multivalued property into my sling model . However, when I read it is only returning single value not multi values.
Sample code :
valueMap.get("cq:tags",String[].class);
or
currentNode.getProperty("cq:tags").values();
Solved! Go to Solution.
Views
Replies
Total Likes
Could you please give us more context like:
1. Is sling model being called on page component or content component?
you can also directly use annotation @Inject or @ValueMap to get values like:
@Inject ()
@Named("cq:tags")
String[] cqTags;
OR
@ValueMapValue(name="cq:tags")
String[] cqTags;
2. Please provide screenshot of crx/de of node where cq:tags property is saved. Ideally the methods you used should have worked.
3. Also, currentNode.getProperty("cq:tags").values(); So, Here, we need to call getValues() to get Value Array instead of values().
Hope this helps!
Thanks,
Nupur
Hello @sateeshreddy
Can you please try using the getTags() from tagManager API?
https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/index.html?com/day/cq...TagManager.html
Tag[] pageTags = tagManager.getTags(pageContentresource);
if (pageTags != null && pageTags.length > 0) {
tags = new String[pageTags.length];
for (int i = 0; i < pageTags.length; i++) {
tags[i] = pageTags[i].getTitle();
}
} else {
tags = ArrayUtils.EMPTY_STRING_ARRAY;
}
Could you please give us more context like:
1. Is sling model being called on page component or content component?
you can also directly use annotation @Inject or @ValueMap to get values like:
@Inject ()
@Named("cq:tags")
String[] cqTags;
OR
@ValueMapValue(name="cq:tags")
String[] cqTags;
2. Please provide screenshot of crx/de of node where cq:tags property is saved. Ideally the methods you used should have worked.
3. Also, currentNode.getProperty("cq:tags").values(); So, Here, we need to call getValues() to get Value Array instead of values().
Hope this helps!
Thanks,
Nupur
It is used in a component and the model is adapted to SlingHTTPRequest.class.
Hi @sateeshreddy
I am assuming you want to get cq:tags property values of page in component. If that is so,
1. First get Page object of currentPage like
@ScriptVariable
private Page currentPage;
2. Then you can get page tags like
Tag[] tags = currentPage.getTags();
OR
currentPage.getProperties ().get("cq:tags", String[].class);
If cq:tags property is part of component properties itself, then follow the @ValueMapValue annotation as mentioned in my previous reply.
Hope it helps!
Thanks,
Nupur
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies