Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inject JCR Properties with colon in Sling Model

Tags:

java

jcr

aem

sling

I'm working with sling models for a project in AEM. I have my sling model setup to inject values to variables. I can setup getters to retrieve properties from the adapted resource as long as the properties have names that don't break java syntax. (For example: title)

My problem is that there are properties I need that break java syntax (for instance jcr:title,etc). I know for the get servlet for image servlet uses underscores in place of periods (file named img.GET.java, class named img_GET) and was curious if there was some character(s) I can use that will be valid java syntax that the injection strategy recognizes to replace with colons.

I know that I can retrieve these properties in other ways but I was wondering if there is a way to retrieve them using injection to keep my code dry.

like image 993
Thomas Avatar asked Feb 05 '15 23:02

Thomas


People also ask

How do you inject resources in a Sling model?

Since 1.1. 0 version of Sling Models you can use @Self annotation to inject models which can be adapted from current adaptable. In this case from Resource of ModelA . Injects the adaptable object itself (if the class of the field matches or is a supertype).

What is Adaptables in Sling model?

The adaptables property determines what source objects can be adapted to the Sling model implementation. Typically this is Resource and/or SlingHttpServletRequest , meaning a Sling resource or Sling request object respectively.


1 Answers

Check out the following blog post:

http://labs.sixdimensions.com/blog/2014-11-21/sling-models-for-fun-and-profit/

In this, Dan provides an example of injecting (ironically enough) the jcr:title property of a Resource. You can simply use the @Named annotation and give it the name of the property you wish to inject.

like image 51
Josh Boyle Avatar answered Oct 06 '22 01:10

Josh Boyle