April 9, 2020
Estimated Post Reading Time ~

AEM Objects Sling Models Injector

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; 
 } 
}


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.