Expand my Community achievements bar.

SOLVED

Is it possible to extend core aem models or extending core models restricted to core aem project ?

Avatar

Level 7
public class ListImpl extends com.adobe.cq.wcm.core.components.internal.models.v1.ListImpl implements List

 

Is it possible to do same in a client aem project or extending core models restricted to core aem project ?

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @sreenu539,

All models located under internal package are not exported by core components bundles. This means you cannot use them directly, this is done by design.

The proper way to extend Core Components model is to use delegation pattern. Here you can find some information with examples:

@Model(adaptables = SlingHttpServletRequest.class,
       adapters = List.class,
       resourceType = "myproject/components/list")
public class ListImpl implements List {

    @Self 
    @Via(type = ResourceSuperType.class)
    private List list;

    /** 
    * using original implementation
    */
    @Override 
    public String getDateFormatString() {
        // place for custom implementation that will be different comparing to orignal one
    }


    /** 
    * using original implementation
    */
    @Override
    public boolean linkItems() {
        // simply run method from Core Components List implementation
        return list.linkItems();
    }

    // place for other methods from List interface
}

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Hi @sreenu539,

All models located under internal package are not exported by core components bundles. This means you cannot use them directly, this is done by design.

The proper way to extend Core Components model is to use delegation pattern. Here you can find some information with examples:

@Model(adaptables = SlingHttpServletRequest.class,
       adapters = List.class,
       resourceType = "myproject/components/list")
public class ListImpl implements List {

    @Self 
    @Via(type = ResourceSuperType.class)
    private List list;

    /** 
    * using original implementation
    */
    @Override 
    public String getDateFormatString() {
        // place for custom implementation that will be different comparing to orignal one
    }


    /** 
    * using original implementation
    */
    @Override
    public boolean linkItems() {
        // simply run method from Core Components List implementation
        return list.linkItems();
    }

    // place for other methods from List interface
}