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/>:

  • resource
  • resourceResolver
  • componentContext
  • pageManager
  • currentPage
  • resourcePage
  • designer
  • currentDesign
  • resourceDesign
  • currentStyle
  • session
  • xssApi

Most injections are available when adapting either a Resource or SlingHttpServletRequest object, with these exceptions, which only work when adapting a SlingHttpServletRequest object:

  • currentPage
  • componentContext
  • xssApi
  • currentDesign

Example

@Model(adaptables = { SlingHttpServletRequest.class, Resource.class })
public class TestModel {

    @Inject
    private Page resourcePage;

    public Page getResourcePage() {
        return resourcePage;
    }
}
Please report any issues with the Feature or documentation on the ACS AEM Commons GitHub Issue tracker.
comments powered by Disqus