I wish to access the current page jcr:content property using POJO class and read properties of current page specifically cq:tags and display that in my html page.
Please help me with the creating POJO class code for it and then accessing it in HTML.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @ShagunMalik ,
Using below code you can access any property and can set in Sling Model Getter, which you can access in HTL-
Map<String, Object> param = new HashMap<>();
param.put(ResourceResolverFactory.SUBSERVICE, "myservice");
try (ResourceResolver resolver = resourceResolverFactory.getServiceResourceResolver(param)) {
Resource res = resolver.getResource("PATH to RESOURCE");
ValueMap pageProperties = resource.getValueMap();
String propertyValue = properties.get("property name", String[].class);
Now, your question about what is subservice-
Just think of subservice as "Level of Access". Means you are trying to get repository access and you define which service I want to use, for example
1. I want to write content to repository, so I need write access so my service name could be writeService (name of service can be anything meaningful)
2. I just want to read some content and no need to write so I can use same writeService (not reccommended) or can create new one with least privileges required.
Now, using Apache Sling User Mapper Service, we just Map this Sub service to system user. system user is actually the one which has read/write access and we use sub service name to map it with system user.
One more thing, there are implicit out of the objects, which you can also use if you want to access the current page properties, you can refer below URL-
https://experienceleague.adobe.com/docs/experience-manager-htl/using/htl/global-objects.html?lang=en
Hi @ShagunMalik ,
you can check this recent thread, using Sling Model and Resource Resolver through subservice, you can easily achieve it.
Hey @Ritesh_Mittal , earlier I was providing specific path but now I wish to access jcr:content properties of each current page. Please explain how to do that.
Views
Replies
Total Likes
Views
Replies
Total Likes
Hi @ShagunMalik ,
Using below code you can access any property and can set in Sling Model Getter, which you can access in HTL-
Map<String, Object> param = new HashMap<>();
param.put(ResourceResolverFactory.SUBSERVICE, "myservice");
try (ResourceResolver resolver = resourceResolverFactory.getServiceResourceResolver(param)) {
Resource res = resolver.getResource("PATH to RESOURCE");
ValueMap pageProperties = resource.getValueMap();
String propertyValue = properties.get("property name", String[].class);
Now, your question about what is subservice-
Just think of subservice as "Level of Access". Means you are trying to get repository access and you define which service I want to use, for example
1. I want to write content to repository, so I need write access so my service name could be writeService (name of service can be anything meaningful)
2. I just want to read some content and no need to write so I can use same writeService (not reccommended) or can create new one with least privileges required.
Now, using Apache Sling User Mapper Service, we just Map this Sub service to system user. system user is actually the one which has read/write access and we use sub service name to map it with system user.
One more thing, there are implicit out of the objects, which you can also use if you want to access the current page properties, you can refer below URL-
https://experienceleague.adobe.com/docs/experience-manager-htl/using/htl/global-objects.html?lang=en
Hey @Ritesh_Mittal , getting error "Map cannot be resolved to a type",
"HashMap cannot be resolved to a type",
"'<>' operator is not allowed for source level below 1.7" and "Resource Specification not allowed for source level below 1.7" and "resourceResolverFactory acnnot be resolved."
Views
Replies
Total Likes
Hi @ShagunMalik ,
You need to import all required classes in your Java class. Also, diamond <> operator requires JDK 1.8, if you already have 1.8 then it means in your eclipse you are using maven version as 1.7. Just check in pom.xml.
Your class should have all imports like below-
https://github.com/riteshmittal/multiple-subservices-system-users/blob/main/MyServiceFirstImpl.java
Hey @Ritesh_Mittal , I just checked my Eclipse is using version as 1.7 and I cannot change it due to policies. can you tell me how do the same task using Node iterator?
Views
Replies
Total Likes
Views
Replies
Total Likes
@ShagunMalik , I dint get, which policies? You can change the maven version via going to file system and open the file in any editor and change.
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies