Expand my Community achievements bar.

SOLVED

How do I get the value of a property given an absolute path?

Avatar

Former Community Member

Given an absolute path to some text content, how to get I get the actual value of that content? For example, I know the absolute path to my node property is /content/userblog/2015/06/blog_post/jcr:content/par/entry, in my .JSP file, how would I get the text value of that property?

1 Accepted Solution

Avatar

Correct answer by
Employee

I hacked up a little example using the excellent AEM Fiddle (part of ACS AEM Tools [0]):

<%@include file="/libs/foundation/global.jsp"%><% %><%@page session="false" contentType="text/html; charset=utf-8" pageEncoding="UTF-8" import="org.apache.sling.api.resource.Resource, org.apache.sling.api.resource.ValueMap"%><%     // Get the text resource Resource textResource = resourceResolver.getResource("/content/userblog/2015/06/blog_post/jcr:content/par/entry");     // Get it's properties ValueMap textResourceProperties = textResource.getValueMap(); %> <%= xssAPI.filterHTML( textResourceProperties.get("text", "no text set") ) %>

[0] http://adobe-consulting-services.github.io/acs-aem-tools/features/aem-fiddle.html

*edit: added XSS protection 

View solution in original post

4 Replies

Avatar

Correct answer by
Employee

I hacked up a little example using the excellent AEM Fiddle (part of ACS AEM Tools [0]):

<%@include file="/libs/foundation/global.jsp"%><% %><%@page session="false" contentType="text/html; charset=utf-8" pageEncoding="UTF-8" import="org.apache.sling.api.resource.Resource, org.apache.sling.api.resource.ValueMap"%><%     // Get the text resource Resource textResource = resourceResolver.getResource("/content/userblog/2015/06/blog_post/jcr:content/par/entry");     // Get it's properties ValueMap textResourceProperties = textResource.getValueMap(); %> <%= xssAPI.filterHTML( textResourceProperties.get("text", "no text set") ) %>

[0] http://adobe-consulting-services.github.io/acs-aem-tools/features/aem-fiddle.html

*edit: added XSS protection 

Avatar

Employee Advisor

For completeness, on JCR you would use something like this:

Item entryItem = session.getItem ("...");
if (!entryItem.isNode()) {
  Property p = Property (entryItem);
}

Avatar

Level 10

You use the JCR API to get node prop values. See this article to learn how to work with AEM and the JCR API: 

https://helpx.adobe.com/experience-manager/using/programmatically-accessing-cq-content-using.html

Avatar

Level 10

As Bruce points out - you can use Sling - which assumes its a resource. That is a great code example. 

The one that i give works at the node level (JCR). 

When working with AEM - you can work at the JCR level (JCR API) or the Sling level (Sling API). 

Also - if you are interested in Sling - look at Sling Models: 

https://helpx.adobe.com/experience-manager/using/sling_models.html