Esta conversación ha sido bloqueada debido a la inactividad. Cree una nueva publicación.
Nivel 1
Nivel 2
Iniciar sesión en la comunidad
Iniciar sesión para ver todas las insignias
Esta conversación ha sido bloqueada debido a la inactividad. Cree una nueva publicación.
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.
¡Resuelto! Ir a solución.
Vistas
Respuestas
Total de me gusta
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
Vistas
Respuestas
Total de me gusta
Hi @ShagunMalik ,
you can check this recent thread, using Sling Model and Resource Resolver through subservice, you can easily achieve it.
Vistas
Respuestas
Total de me gusta
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.
Vistas
Respuestas
Total de me gusta
Vistas
Respuestas
Total de me gusta
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
Vistas
Respuestas
Total de me gusta
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."
Vistas
Respuestas
Total de me gusta
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
Vistas
Respuestas
Total de me gusta
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?
Vistas
Respuestas
Total de me gusta
Vistas
Respuestas
Total de me gusta
@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.
Vistas
Respuestas
Total de me gusta
Vistas
Respuestas
Total de me gusta
Vistas
me gusta
Respuestas
Vistas
me gusta
Respuestas
Vistas
me gusta
Respuestas