Inject JCR Properties with colon in Sling Model
Asked Answered
C

1

6

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.

Carpus answered 5/2, 2015 at 23:43 Comment(0)
G
3

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.

Gilberto answered 6/2, 2015 at 1:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.