April 9, 2020
Estimated Post Reading Time ~

Child Resource From Request Injector

Purpose
This injector is similar to the standard @ChildResource injector provided by the sling, but with a key difference in that it uses a mock request object pointed to the resource path as the adaptable, allowing the sling model to reference the request and other sling bindings not otherwise accessible when adapting a resource directly. 
This is particularly useful when injecting instances of WCM Core components, which are generally not adaptable from Resource and thus fail to inject via the standard @ChildResource injector.

How to Use
The feature is very similar in usage to the standard ChildResource annotation.

Example
@Model(adaptables = {SlingHttpServletRequest.class}) 
public final class ParentModel { 
    @ChildResourceFromRequest 
    private ChildModel child; 

    @ChildResourceFromRequest 
    private List<ChildModel> childList; 
}


By aem4beginner

1 comment:

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