AEM Objects Sling Models Injector
Available since version 1.6.0
Purpose
Allows for Sling Models classes and interfaces to be injected with common AEM-related objects, namely those made available using <cq:defineObjects/>:
resourceresourceResolvercomponentContext-
pageManager currentPageresourcePagedesignercurrentDesignresourceDesigncurrentStylesessionxssApi
Also allows some direct injections that adapt from resourceResolver. (since 6.6.1) This adapts if the field has the appropriate class declared.
Most injections are available when adapting either a Resource or SlingHttpServletRequest object, with these exceptions, which only work when adapting a SlingHttpServletRequest object:
currentPagecomponentContextxssApicurrentDesign
Example
@Model(adaptables = { SlingHttpServletRequest.class, Resource.class })
public class TestModel {
@AemObject
private Page resourcePage;
public Page getResourcePage() {
return resourcePage;
}
}