Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

How to create custom Sling Model for Pages that inherits from Core Component model?


Level 4

All of the pages on my site have their own sling types set up, and the sling:resourceSuperType inheritance is:


myapp/components/pages/page-type --> sling:resourceSuperType --> myapp/components/page --> core/wcm/components/page/v3/page


Now, I am trying to create a model for myapp/components/page called BasePageModel.  I am using queryBuilder to retrieve a list of resources, and I want to adapt each one to an instance of BasePageModel to simplify the logic around reading properties.


What model can I inherit from in Java to get some base functionality for core/wcm/components/page/v3/page?


For instance, I don't want to rewrite the logic around Vanity URLs or retrieving the page's featured image.  How can I simply inherit more base functionality from the core components and extend it with my own custom properties in Java?


I've found this page interface: aem-core-wcm-components/ at main · adobe/aem-core-wcm-components ( ... this is basically the functionality I want to inherit on my BasePageModel (not override).


Here's the corresponding model in Core components for page v3 (ultimately what I am inheriting from in sling): aem-core-wcm-components/ at main · adobe/aem-core-wcm-components ( ... but this is marked internal.  It's also only adaptable from a SlingHttpServletRequest, where as I need to adapt to this model from a Resource returned by a call.


How can I re-use the functionality of PageImpl from core components?


I tried injecting like this:


@Model(adaptables = { SlingHttpServletRequest.class, Resource.class }, 
       adapters = BasePage.class, // a simple interface
       resourceType = BasePageImpl.RESOURCE_TYPE, 
       defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class BasePageImpl implements BasePage  {
    final public static String RESOURCE_TYPE = "myapp/components/page";

    private com.adobe.cq.wcm.core.components.models.Page page; // null at this point



2 Replies


Level 4

I tried that, but the page object is null.  I suspect it's because I'm adapting from a resource and not a servlet request?




    private com.adobe.cq.wcm.core.components.models.Page page; // null at this point