Need clarification on topic https://sling.apache.org/documentation/tutorials-how-tos/getting-resources-and-properties-in-sling.html | Community
Skip to main content
Level 9
October 16, 2015
Solved

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

  • October 16, 2015
  • 3 replies
  • 651 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Feike_Visser1

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.html#getValueMap()

3 replies

Feike_Visser1
Adobe Employee
Feike_Visser1Adobe EmployeeAccepted solution
Adobe Employee
October 16, 2015

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.html#getValueMap()

askdctmAuthor
Level 9
October 16, 2015

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.

Feike_Visser1
Adobe Employee
Adobe Employee
October 16, 2015

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.