Hey Community
I have wriiten this basic code to get cq:tags property of current page
public Void activate throws exception{
rootpage=getCurrentPage;
Resource res = getResourceResolver.getResource(rootpage.getPath()+"/jcr:content/");
ValueMap pageProperties = res .getValueMap();
tag= (String) pageProperties.get("cq:tags", "Default value");
logger.info(tag);
}
When I'm using creating object using HTL statement in HTMl file it is not displaying anything on page and error log says "AEM failed to activate Use class"
How to resolve it?
@Dipti_Chauhan Please suggest.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @ShagunMalik
BTW there is no need to add slash after jcr:content. It should be
Resource res = getResourceResolver.getResource(rootpage.getPath()+"/jcr:content");
Hi @ShagunMalik ,
You must be getting some exception like NullPoineterException or something in the logs which is happening inside Active method of your class. Could you provide the error logs?
Views
Replies
Total Likes
Hi @Sh
May be there is some exception in activate method. Please debug your code using debugger and find out where you getting exception.
And normally you should not write any logic inside activate method. Create different getter to get properties because if there is any issue in you code written within activate method your class activation will get failed
Thanks
Dipti
Hi @ShagunMalik
BTW there is no need to add slash after jcr:content. It should be
Resource res = getResourceResolver.getResource(rootpage.getPath()+"/jcr:content");
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
@Dipti_Chauhan, Here is my complete java code:
Public class CategoryUse extends WCMUsePojo{
private static final Logger logger =LoggerFactory.getlogger(CategoryUse.class)
private String tag;
private Page rootpage;
ValueMap pageProperties;
public String getTag{
return tag;
}
public void activate() throws exception{
rootpage=getCurrentPage;
Resource res = getResourceResolver.getResource(rootpage.getPath()+"/jcr:content");
ValueMap pageProperties = res .getValueMap();
tag= (String) pageProperties.get("cq:tags");
logger.info(tag);
}
}
}
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Resource res = getResourceResolver.getResource(rootpage.getPath()+"/jcr:content/");
remove the slash from the end
Resource res = getResourceResolver.getResource(rootpage.getPath()+"/jcr:content");
if still the issue persists add loggers or run your class in debug mode to get the exact line where there is exception
Hope this helps
Hi @ShagunMalik ,
Could you please verify below line
tag= (String) pageProperties.get("cq:tags", "Default value");
By Default cq:tags are String Array not a String Field
String[] tagArrays = pageProperties.get("cq:tags", String[].class);
if(Objects.nonNull(tagArrays ) && tagArrays .length>0) {
tag = tagArrays[0]; -- will give first value in array.
}
Hey, @GnanendraPonnala I get your point but Even if I'm trying to access any other property of page which is of type String such as cq:template then still it is not working.
Views
Replies
Total Likes
Thank you everyone.
Views
Replies
Total Likes