Expand my Community achievements bar.

SOLVED

Sling Model in AEM6.0 - How to get the path of the original resource

Avatar

Level 3

Hi

I'm currently using Sling Models to adapt several Resources to customized models. One of my models must be aware of the original resource it was adapted from (I basically need the name of the node but I guess it wouldn't hurt to have the full path as it will provide me with more flexibility). It seems that @SlingObject is what I'm looking for. Unfortunately AEM 6.0 is using Sling Models 1.0.x and SlingObject requires 1.1.x or so. Updating to AEM 6.1 is currently no option so I was wondering if there is any other way that would get me the information I need.

As an alternative I could install the 1.1.x bundles in AEM6.0 but I'm not sure if it is safe to do so. I'm pretty sure it won't break our custom code but what about the AEM6 code base?

Any advice/help is greatly appreciated.

Cheers

1 Accepted Solution

Avatar

Correct answer by
Level 6

You can use the :

@Source('sling-object')

It will have the same effect as @SlingObject

 

Att.

View solution in original post

2 Replies

Avatar

Correct answer by
Level 6

You can use the :

@Source('sling-object')

It will have the same effect as @SlingObject

 

Att.

Avatar

Level 3

Hi

Thank you for your response. Unfortunately it doesn't seem to work for me in this particular case (original object was of type Resource.class). However I was able to get the resource by simply adding @Inject private Resource resource; to the class in question. I'll keep the @Source annotation in mind though. Thanks again for your help.

Cheers