Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Need clarification on topic https://sling.apache.org/documentation/tutorials-how-tos/getting-resources-and-properties-in-sling.html

Avatar

Level 9

Hi All,

It is mentioned here that 

Note: resource.adaptTo(Node.class) may return null if the resource is not backed by a JCR node. This is particularly the case for NonExistingResource resources or resource provided by a non-JCR resource provider.

1] But isn't it something like every resource[probably a node] always has a jcr:content associated with it.

Can you please let me know on this.

1 Accepted Solution

Avatar

Correct answer by
Employee

Not in all cases, you can create a so called SyntheticResource

https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/org/apache/sling/api/resource/SyntheticResource.html

I would always go for resource.getValueMap(), this is much easier way to access properties.

https://docs.adobe.com/docs/en/aem/6-0/develop/ref/javadoc/org/apache/sling/api/resource/Resource.ht...()

View solution in original post

3 Replies

Avatar

Correct answer by
Employee

Not in all cases, you can create a so called SyntheticResource

https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/org/apache/sling/api/resource/SyntheticResource.html

I would always go for resource.getValueMap(), this is much easier way to access properties.

https://docs.adobe.com/docs/en/aem/6-0/develop/ref/javadoc/org/apache/sling/api/resource/Resource.ht...()

Avatar

Level 9

Hi Feike,

Thank you for your reply. 

I was not aware that something like this exists. But what exactly would be the purpose of SyntheticResource. If you can provide any example, it would be helpful.

Avatar

Employee

For example you have a servlet that is registered on a path like "/bin/xyz". In this case request.getResource() isn't pointing you to a 'real/existing' resource.